]> Savannah Git Hosting - gnulib.git/commitdiff
tests: fix signed overflow issues
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 21 Mar 2021 21:52:08 +0000 (14:52 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 21 Mar 2021 21:52:34 +0000 (14:52 -0700)
* tests/test-dynarray.c (value_at): Avoid undefined behavior
in signed integer multiplication.
* tests/test-scratch-buffer.c (byte_at): Likewise, for the
theoretically-possible case where size_t is narrower than int.

ChangeLog
tests/test-dynarray.c
tests/test-scratch-buffer.c

index 76ea9c3ebcc03e1934bffa1f7fbe73b50d1da506..6c4d4b5f2f2fcebe2466fe175d566ba159422637 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2021-03-21  Paul Eggert  <eggert@cs.ucla.edu>
+
+       tests: fix signed overflow issues
+       * tests/test-dynarray.c (value_at): Avoid undefined behavior
+       in signed integer multiplication.
+       * tests/test-scratch-buffer.c (byte_at): Likewise, for the
+       theoretically-possible case where size_t is narrower than int.
+
 2021-03-21  Bruno Haible  <bruno@clisp.org>
 
        doc: More updates.
index 4308148f8986c83345f3d397ee09ec3c5f5a9668..c3f9a29b542df06b24b63ae04ce61a8d9d16e0b0 100644 (file)
@@ -28,7 +28,7 @@
 #define N 100000
 
 static int
-value_at (int i)
+value_at (long long int i)
 {
   return (i % 13) + ((i * i) % 251);
 }
index f05c84fa468fadd82f8ef696c52f328018bc660f..517d73fd765a6959c6897478fe8add21d9c8d602 100644 (file)
@@ -24,7 +24,7 @@
 #include "macros.h"
 
 static int
-byte_at (size_t i)
+byte_at (unsigned long long int i)
 {
   return ((i % 13) + ((i * i) % 251)) & 0xff;
 }