aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/pgbench/pgbench.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 72b952056fe..a9a929d12a2 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -2259,7 +2259,8 @@ evalStandardFunc(CState *st,
case PGBENCH_RANDOM_ZIPFIAN:
{
int64 imin,
- imax;
+ imax,
+ delta;
Assert(nargs >= 2);
@@ -2268,12 +2269,13 @@ evalStandardFunc(CState *st,
return false;
/* check random range */
- if (imin > imax)
+ if (unlikely(imin > imax))
{
fprintf(stderr, "empty range given to random\n");
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 */
fprintf(stderr, "random range is too large\n");