]> Savannah Git Hosting - gnulib.git/commitdiff
explicit_bzero test: Fix test failure due to GCC optimizations.
authorBruno Haible <bruno@clisp.org>
Sun, 29 Aug 2021 16:54:54 +0000 (18:54 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 29 Aug 2021 17:04:36 +0000 (19:04 +0200)
* tests/test-explicit_bzero.c (do_secret_stuff): Use static variable
'last_stackbuf'.
(main): Use an 'if' to combine the two do_secret_stuff invocations.

ChangeLog
tests/test-explicit_bzero.c

index 04ddcd1f3fbda1cc403427c90173478048b1c838..ce9a2b3664eb9dd68a88d12699adca84b2bda76b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2021-08-29  Bruno Haible  <bruno@clisp.org>
+
+       explicit_bzero test: Fix test failure due to GCC optimizations.
+       * tests/test-explicit_bzero.c (do_secret_stuff): Use static variable
+       'last_stackbuf'.
+       (main): Use an 'if' to combine the two do_secret_stuff invocations.
+
 2021-08-29  Paul Eggert  <eggert@cs.ucla.edu>
 
        dfa: port to non-gnulib
@@ -6,6 +13,8 @@
        * lib/dfa.h (_GL_ATTRIBUTE_DEALLOC) [!_GL_ATTRIBUTE_MALLOC]:
        Add missing definition.
 
+2021-08-29  Paul Eggert  <eggert@cs.ucla.edu>
+
        base32, base64: fix broken tests
        Problem reported by Bruno Haible in:
        https://lists.gnu.org/r/bug-gnulib/2021-08/msg00170.html
index 14f0ead2b73e1b686e31f7cd4eee35ac74520e02..15a2526983c0da55faae51edd9a18074ce905a9b 100644 (file)
@@ -139,16 +139,22 @@ test_heap (void)
 static int _GL_ATTRIBUTE_NOINLINE
 do_secret_stuff (volatile int pass)
 {
+  static char *last_stackbuf;
   char stackbuf[SECRET_SIZE];
   if (pass == 1)
     {
       memcpy (stackbuf, SECRET, SECRET_SIZE);
       explicit_bzero (stackbuf, SECRET_SIZE);
+      last_stackbuf = stackbuf;
       return 0;
     }
   else /* pass == 2 */
     {
-      return memcmp (zero, stackbuf, SECRET_SIZE) != 0;
+      /* Use last_stackbuf here, because stackbuf may be allocated at a
+         different address than last_stackbuf.  This can happen
+         when the compiler splits this function into different functions,
+         one for pass == 1 and one for pass != 1.  */
+      return memcmp (zero, last_stackbuf, SECRET_SIZE) != 0;
     }
 }
 
@@ -158,10 +164,17 @@ test_stack (void)
   int count = 0;
   int repeat;
 
-  for (repeat = 1000; repeat > 0; repeat--)
+  for (repeat = 2 * 1000; repeat > 0; repeat--)
     {
-      do_secret_stuff (1);
-      count += do_secret_stuff (2);
+      /* This odd way of writing two consecutive statements
+           do_secret_stuff (1);
+           count += do_secret_stuff (2);
+         ensures that the two do_secret_stuff calls are performed with the same
+         stack pointer value, on m68k.  */
+      if ((repeat % 2) == 0)
+        do_secret_stuff (1);
+      else
+        count += do_secret_stuff (2);
     }
   /* If explicit_bzero works, count is near 0.  (It may be > 0 if there were
      some asynchronous signal invocations between the two calls of