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

Commitbe567de

Browse files
committed
Don't depend on -fwrapv semantics in pgbench's random() function.
Instead use the common/int.h functions to check for integer overflowin a more C-standard-compliant fashion. This is motivated by recentfailures on buildfarm member moonjelly, where it appears thatdevelopment-tip gcc is optimizing without regard to the -fwrapvswitch. Presumably that's a gcc bug that will be fixed soon, butwe might as well install cleaner coding here rather than wait.(This does not address the question of whether we'll ever be ableto get rid of using -fwrapv. Testing shows that this spot is theonly place where doing so creates visible regression test failures,but unfortunately that proves very little.)Back-patch to v12. The common/int.h functions exist in v11, butthat branch doesn't use them in any client-side code. I judgethat this case isn't interesting enough in the real world to takeeven a small risk of issues from being the first such use.Tom Lane and Fabien CoelhoDiscussion:https://postgr.es/m/73927.1624815543@sss.pgh.pa.us
1 parent741deb2 commitbe567de

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎src/bin/pgbench/pgbench.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,8 @@ evalStandardFunc(CState *st,
22782278
casePGBENCH_RANDOM_ZIPFIAN:
22792279
{
22802280
int64imin,
2281-
imax;
2281+
imax,
2282+
delta;
22822283

22832284
Assert(nargs >=2);
22842285

@@ -2287,12 +2288,13 @@ evalStandardFunc(CState *st,
22872288
return false;
22882289

22892290
/* check random range */
2290-
if (imin>imax)
2291+
if (unlikely(imin>imax))
22912292
{
22922293
pg_log_error("empty range given to random");
22932294
return false;
22942295
}
2295-
elseif (imax-imin<0|| (imax-imin)+1<0)
2296+
elseif (unlikely(pg_sub_s64_overflow(imax,imin,&delta)||
2297+
pg_add_s64_overflow(delta,1,&delta)))
22962298
{
22972299
/* prevent int overflows in random functions */
22982300
pg_log_error("random range is too large");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp