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

Commit01697e9

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 parentba135fa commit01697e9

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
@@ -2450,7 +2450,8 @@ evalStandardFunc(CState *st,
24502450
casePGBENCH_RANDOM_ZIPFIAN:
24512451
{
24522452
int64imin,
2453-
imax;
2453+
imax,
2454+
delta;
24542455

24552456
Assert(nargs >=2);
24562457

@@ -2459,12 +2460,13 @@ evalStandardFunc(CState *st,
24592460
return false;
24602461

24612462
/* check random range */
2462-
if (imin>imax)
2463+
if (unlikely(imin>imax))
24632464
{
24642465
pg_log_error("empty range given to random");
24652466
return false;
24662467
}
2467-
elseif (imax-imin<0|| (imax-imin)+1<0)
2468+
elseif (unlikely(pg_sub_s64_overflow(imax,imin,&delta)||
2469+
pg_add_s64_overflow(delta,1,&delta)))
24682470
{
24692471
/* prevent int overflows in random functions */
24702472
pg_log_error("random range is too large");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp