On 4/18/21 5:04 PM, Bruno Haible wrote:
Paul Eggert wrote:
I installed the attached instead, as this is simpler.

And I'm already starting to wonder whether testing for ptrdiff_t overflow was such a good idea. I installed the attached further patch to try to pacify GCC diagnostics about them.

If these ptrdiff_t tests turn out to be too much trouble we can always withdraw them.
>From 11e793833378de5a5978b296af1c0993f7305eda Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sun, 18 Apr 2021 21:18:00 -0700
Subject: [PATCH] malloc-gnu-tests: pacify -Walloc-size-larger-than
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* tests/test-malloc-gnu.c (main):
* tests/test-realloc-gnu.c (main): Hide true intentions from GCC,
to prevent diagnostics like “warning: argument 1 value
‘9223372036854775808’ exceeds maximum object size
9223372036854775807 [-Walloc-size-larger-than=]”.
---
 ChangeLog                | 7 +++++++
 tests/test-malloc-gnu.c  | 6 +++---
 tests/test-realloc-gnu.c | 6 +++---
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2c7edd59a..0146e1594 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2021-04-18  Paul Eggert  <egg...@cs.ucla.edu>
 
+	malloc-gnu-tests: pacify -Walloc-size-larger-than
+	* tests/test-malloc-gnu.c (main):
+	* tests/test-realloc-gnu.c (main): Hide true intentions from GCC,
+	to prevent diagnostics like “warning: argument 1 value
+	‘9223372036854775808’ exceeds maximum object size
+	9223372036854775807 [-Walloc-size-larger-than=]”.
+
 	safe-alloc: fix pointer implementation
 	The old implementation assumed that all pointers use the same
 	internal representation, but the C standard doesn’t guarantee
diff --git a/tests/test-malloc-gnu.c b/tests/test-malloc-gnu.c
index ce7e4fec2..e1dfde452 100644
--- a/tests/test-malloc-gnu.c
+++ b/tests/test-malloc-gnu.c
@@ -20,7 +20,7 @@
 #include <stdint.h>
 
 int
-main ()
+main (int argc, char **argv)
 {
   /* Check that malloc (0) is not a NULL pointer.  */
   char *p = malloc (0);
@@ -31,8 +31,8 @@ main ()
   /* Check that malloc (n) fails when n exceeds PTRDIFF_MAX.  */
   if (PTRDIFF_MAX < SIZE_MAX)
     {
-      size_t n = PTRDIFF_MAX, n1 = n + 1;
-      if (malloc (n1) != NULL)
+      size_t one = argc != 12345;
+      if (malloc (PTRDIFF_MAX + one) != NULL)
         return 1;
     }
 
diff --git a/tests/test-realloc-gnu.c b/tests/test-realloc-gnu.c
index 9c7344f15..b62ee6bad 100644
--- a/tests/test-realloc-gnu.c
+++ b/tests/test-realloc-gnu.c
@@ -20,7 +20,7 @@
 #include <stdint.h>
 
 int
-main ()
+main (int argc, char **argv)
 {
   /* Check that realloc (NULL, 0) is not a NULL pointer.  */
   char *p = realloc (NULL, 0);
@@ -31,8 +31,8 @@ main ()
      PTRDIFF_MAX.  */
   if (PTRDIFF_MAX < SIZE_MAX)
     {
-      size_t n = PTRDIFF_MAX, n1 = n + 1;
-      if (realloc (p, n1) != NULL)
+      size_t one = argc != 12345;
+      if (realloc (p, PTRDIFF_MAX + one) != NULL)
         return 1;
     }
 
-- 
2.27.0

Reply via email to