Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf0f200

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 couldoverflow, leading to bogus output as reported in bug #5993 from NicolaCossu. This isn't likely to ever happen in the intended usage of thefunction (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 parentf8ebe3b commitaf0f200

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+
int64val;
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)

[8]ページ先頭

©2009-2025 Movatter.jp