bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: bug-gnulib@gnu.org
Cc: Paul Eggert <eggert@cs.ucla.edu>
Subject: [PATCH] tests: fix signed overflow issues
Date: Sun, 21 Mar 2021 14:52:53 -0700	[thread overview]
Message-ID: <20210321215253.1105328-1-eggert@cs.ucla.edu> (raw)

* 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                   | 8 ++++++++
 tests/test-dynarray.c       | 2 +-
 tests/test-scratch-buffer.c | 2 +-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 76ea9c3eb..6c4d4b5f2 100644
--- 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.
diff --git a/tests/test-dynarray.c b/tests/test-dynarray.c
index 4308148f8..c3f9a29b5 100644
--- a/tests/test-dynarray.c
+++ b/tests/test-dynarray.c
@@ -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);
 }
diff --git a/tests/test-scratch-buffer.c b/tests/test-scratch-buffer.c
index f05c84fa4..517d73fd7 100644
--- a/tests/test-scratch-buffer.c
+++ b/tests/test-scratch-buffer.c
@@ -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;
 }
-- 
2.30.2



             reply	other threads:[~2021-03-21 21:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-21 21:52 Paul Eggert [this message]
2021-03-22  0:28 ` [PATCH] tests: fix signed overflow issues Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210321215253.1105328-1-eggert@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).