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

Commit6ba0d8d

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 parent147d626 commit6ba0d8d

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
@@ -497,9 +497,15 @@ pg_size_pretty(PG_FUNCTION_ARGS)
497497
(size+mult /2) /mult);
498498
else
499499
{
500+
/* Here we have to worry about avoiding overflow */
501+
int64val;
502+
500503
mult *=1024;
504+
val=size /mult;
505+
if ((size %mult) >= (mult /2))
506+
val++;
501507
snprintf(buf,sizeof(buf),INT64_FORMAT" TB",
502-
(size+mult /2) /mult);
508+
val);
503509
}
504510
}
505511
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp