bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: coreutils snapshot vs gcc7-to-be: new test-calloc-gnu.c and test-can


From: Bruno Haible
Subject: Re: coreutils snapshot vs gcc7-to-be: new test-calloc-gnu.c and test-canonicalize.c warnings
Date: Sun, 05 Mar 2017 02:21:52 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-64-generic; KDE/5.18.0; x86_64; ; )

Hi Jim,

Jim Meyering wrote:
> I've just fixed that with the attached and just-pushed gnulib patch:

You "fixed" it by disabling a valuable test! I propose to restore the test
and instead only disable GCC's ability to produce a warning. Like this:


2017-03-04  Bruno Haible  <address@hidden>

        test-calloc-gnu: Reenable test also for GCC 7.
        * tests/test-calloc-gnu.c (eight): New function.
        (main): Don't skip test; use eight() instead.

diff --git a/tests/test-calloc-gnu.c b/tests/test-calloc-gnu.c
index 3f964c3..7f5a1e1 100644
--- a/tests/test-calloc-gnu.c
+++ b/tests/test-calloc-gnu.c
@@ -18,6 +18,20 @@
 
 #include <stdlib.h>
 
+/* Return 8.
+   Usual compilers are not able to infer something about the return value.  */
+static unsigned int
+eight (void)
+{
+  unsigned int x = rand ();
+  unsigned int y = x * x * x * x;
+  x++; y |= x * x * x * x;
+  x++; y |= x * x * x * x;
+  x++; y |= x * x * x * x;
+  y = y >> 1;
+  return y & -y;
+}
+
 int
 main ()
 {
@@ -27,19 +41,15 @@ main ()
     return 1;
   free (p);
 
-#if __GNUC__ < 7
-  /* GCC7's -Werror=alloc-size-larger-than= would cause the following error
-     to be detected at compile time, so skip the test for GCC7 and newer.  */
-
   /* Check that calloc fails when requested to allocate a block of memory
-     larger than SIZE_MAX bytes.  */
-  p = calloc ((size_t) -1 / 8 + 1, 8);
+     larger than SIZE_MAX bytes.
+     We use eight (), not 8, to avoid a compiler warning from GCC 7.  */
+  p = calloc ((size_t) -1 / 8 + 1, eight ());
   if (p != NULL)
     {
       free (p);
       return 1;
     }
-#endif
 
   return 0;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]