postgres.git / summary / log / commit / refs
commit 7e2af1fb1118a547bd831fca3afbc3ff80ebf089
Author: Dean Rasheed <dean.a.rasheed@gmail.com>
Date: Sat Oct 25 10:08:46 2025 +0000
First released in: 19.0
Guard against division by zero in test_int128 module.
When testing 128/32-bit division in the test_int128 test module, make
sure that we don't attempt to divide by zero.
While at it, use pg_prng_int64() and pg_prng_int32() to generate the
random numbers required for the tests, rather than pg_prng_uint64().
This eliminates the need for any implicit or explicit type casts.
Author: Dean Rasheed <dean.a.rasheed@gmail.com>
Reported-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/da4wqngd6gwz5s4yf5y5f75xj7gpja62l4dbp6w4j3vs7fcjue@upvolcu4e6o2
src/test/modules/test_int128/test_int128.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/test/modules/test_int128/test_int128.c b/src/test/modules/test_int128/test_int128.c
index c9c17a73a4e..1efd4ff68b3 100644
--- a/src/test/modules/test_int128/test_int128.c
+++ b/src/test/modules/test_int128/test_int128.c
@@ -90,17 +90,21 @@ main(int argc, char **argv)
while (count-- > 0)
{
- int64 x = pg_prng_uint64(&pg_global_prng_state);
- int64 y = pg_prng_uint64(&pg_global_prng_state);
- int64 z = pg_prng_uint64(&pg_global_prng_state);
- int64 w = pg_prng_uint64(&pg_global_prng_state);
- int32 z32 = (int32) z;
+ int64 x = pg_prng_int64(&pg_global_prng_state);
+ int64 y = pg_prng_int64(&pg_global_prng_state);
+ int64 z = pg_prng_int64(&pg_global_prng_state);
+ int64 w = pg_prng_int64(&pg_global_prng_state);
+ int32 z32 = pg_prng_int32(&pg_global_prng_state);
test128 t1;
test128 t2;
test128 t3;
int32 r1;
int32 r2;
+ /* prevent division by zero in the 128/32-bit division test */
+ while (z32 == 0)
+ z32 = pg_prng_int32(&pg_global_prng_state);
+
/* check unsigned addition */
t1.hl.hi = x;
t1.hl.lo = y;
[parent: 5173bfd0443e]