diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 9b3c17d1d9..338c0152a2 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -2278,7 +2278,8 @@ evalStandardFunc(CState *st, case PGBENCH_RANDOM_ZIPFIAN: { int64 imin, - imax; + imax, + delta; Assert(nargs >= 2); @@ -2287,12 +2288,13 @@ evalStandardFunc(CState *st, return false; /* check random range */ - if (imin > imax) + if (unlikely(imin > imax)) { pg_log_error("empty range given to random"); return false; } - else if (imax - imin < 0 || (imax - imin) + 1 < 0) + else if (unlikely(pg_sub_s64_overflow(imax, imin, &delta) || + pg_add_s64_overflow(delta, 1, &delta))) { /* prevent int overflows in random functions */ pg_log_error("random range is too large");