Re: Fix overflow in pg_size_pretty

2024-07-28 Thread David Rowley
On Sun, 28 Jul 2024 at 16:30, Joseph Koshakow wrote: > Attached is an updated patch with your approach. I removed the 0 from > the negative case because I think it was unnecessary, but happy to add > it back in if I missed something. I made a few adjustments and pushed this. I did keep the 0 - p

Re: Fix overflow in pg_size_pretty

2024-07-27 Thread Joseph Koshakow
cf294e9f687 Mon Sep 17 00:00:00 2001 From: Joseph Koshakow Date: Sat, 27 Jul 2024 15:06:09 -0400 Subject: [PATCH] Fix overflow in pg_size_pretty This commit removes an overflow from pg_size_pretty that causes PG_INT64_MIN to by displayed with the bytes unit instead of the PB unit. --- src/backend/utils/

Re: Fix overflow in pg_size_pretty

2024-07-27 Thread David Rowley
On Sun, 28 Jul 2024 at 13:10, Joseph Koshakow wrote: > > On Sat, Jul 27, 2024 at 8:00 PM David Rowley wrote: > > What if we spelt it out the same way as pg_lltoa() does? > > > > i.e: uint64 usize = size < 0 ? 0 - (uint64) size : (uint64) size; > > My understanding of pg_lltoa() is that it produce

Re: Fix overflow in pg_size_pretty

2024-07-27 Thread Joseph Koshakow
On Sat, Jul 27, 2024 at 8:00 PM David Rowley wrote: > > On Sun, 28 Jul 2024 at 11:06, Joseph Koshakow wrote: >> > + uint64 usize = size < 0 ? (uint64) (-size) : (uint64) size; >> >> I think that the explicit test for PG_INT64_MIN is still required. If >> `size` is equal to PG_INT64_MIN then `-siz

Re: Fix overflow in pg_size_pretty

2024-07-27 Thread David Rowley
On Sun, 28 Jul 2024 at 11:06, Joseph Koshakow wrote: > > + uint64 usize = size < 0 ? (uint64) (-size) : (uint64) size; > > I think that the explicit test for PG_INT64_MIN is still required. If > `size` is equal to PG_INT64_MIN then `-size` will overflow. You end up > with the correct behavior if `

Re: Fix overflow in pg_size_pretty

2024-07-27 Thread Joseph Koshakow
On Sat, Jul 27, 2024 at 6:28 PM David Rowley wrote: > > On Sun, 28 Jul 2024 at 07:18, Joseph Koshakow wrote: >> Attached is a patch that resolves an overflow in pg_size_pretty() that >> resulted in unexpected behavior when PG_INT64_MIN was passed in as an >> argument. > > Could we just fix this m

Re: Fix overflow in pg_size_pretty

2024-07-27 Thread David Rowley
On Sun, 28 Jul 2024 at 07:18, Joseph Koshakow wrote: > Attached is a patch that resolves an overflow in pg_size_pretty() that > resulted in unexpected behavior when PG_INT64_MIN was passed in as an > argument. Could we just fix this more simply by assigning the absolute value of the signed variab

Re: Fix overflow in pg_size_pretty

2024-07-27 Thread Joseph Koshakow
e `::bigint` cast is omitted from my test. Turns out it was just an order of operations issue. Fix is attached. Thanks, Joseph Koshakow From 1224087ab4e13a107b51ac17c77e83dc7db37ef9 Mon Sep 17 00:00:00 2001 From: Joseph Koshakow Date: Sat, 27 Jul 2024 15:06:09 -0400 Subject: [PATCH] Fix overflow in

Fix overflow in pg_size_pretty

2024-07-27 Thread Joseph Koshakow
2024 15:06:09 -0400 Subject: [PATCH] Fix overflow in pg_size_pretty This commit removes an overflow from pg_size_pretty that causes PG_INT64_MIN to by displayed with the bytes unit instead of the PB unit. --- src/backend/utils/adt/dbsize.c | 3 ++- src/include/common/int.h | 1