Skip to content

Commit af0f200

Browse files
committed
Fix pg_size_pretty() to avoid overflow for inputs close to INT64_MAX.
The expression that tried to round the value to the nearest TB could overflow, leading to bogus output as reported in bug #5993 from Nicola Cossu. This isn't likely to ever happen in the intended usage of the function (if it could, we'd be needing to use a wider datatype instead); but it's not hard to give the expected output, so let's do so.
1 parent f8ebe3b commit af0f200

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/backend/utils/adt/dbsize.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,15 @@ pg_size_pretty(PG_FUNCTION_ARGS)
490490
(size + mult / 2) / mult);
491491
else
492492
{
493+
/* Here we have to worry about avoiding overflow */
494+
int64 val;
495+
493496
mult *= 1024;
497+
val = size / mult;
498+
if ((size % mult) >= (mult / 2))
499+
val++;
494500
snprintf(buf, sizeof(buf), INT64_FORMAT " TB",
495-
(size + mult / 2) / mult);
501+
val);
496502
}
497503
}
498504
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy