]> Savannah Git Hosting - gnulib.git/commitdiff
explicit_bzero-tests: pacify GCC
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 18 Jul 2021 04:52:45 +0000 (23:52 -0500)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 18 Jul 2021 04:55:47 +0000 (23:55 -0500)
Redo to pacify -Wmaybe-uninitialized with
GCC 11.1.1 20210531 (Red Hat 11.1.1-3) x86-64.
* tests/test-explicit_bzero.c (stackbuf): New static pointer.
(do_secret_stuff): Use it.
(test_stack): Set it to a local buffer.

ChangeLog
tests/test-explicit_bzero.c

index 6ba44e7df68651e1b1ae19bf06cb91a0609578f1..1caabff621f4324816d87b622bb939c7900cbc61 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2021-07-17  Paul Eggert  <eggert@cs.ucla.edu>
 
+       explicit_bzero-tests: pacify GCC
+       Redo to pacify -Wmaybe-uninitialized with
+       GCC 11.1.1 20210531 (Red Hat 11.1.1-3) x86-64.
+       * tests/test-explicit_bzero.c (stackbuf): New static pointer.
+       (do_secret_stuff): Use it.
+       (test_stack): Set it to a local buffer.
+
        posixtm: pacify latest GCC
        Also, modernize while I’m at it.
        * lib/posixtm.c: Include c-ctype.h, idx.h, intprops.h, verify.h
index cdb839245ee3c9f7e1707df5aae0d6dee074fd54..c42aba93fa8eabad1b8b9321fe75344f47734b62 100644 (file)
@@ -126,12 +126,12 @@ test_heap (void)
 /* There are two passes:
      1. Put a secret in memory and invoke explicit_bzero on it.
      2. Verify that the memory has been erased.
-   Implement them in the same function, so that they access the same memory
-   range on the stack.  */
+   Access the memory via a volatile pointer, so the compiler
+   does not assume the pointer's value and optimize away accesses.  */
+static char *volatile stackbuf;
 static int _GL_ATTRIBUTE_NOINLINE
 do_secret_stuff (volatile int pass)
 {
-  char stackbuf[SECRET_SIZE];
   if (pass == 1)
     {
       memcpy (stackbuf, SECRET, SECRET_SIZE);
@@ -147,6 +147,8 @@ do_secret_stuff (volatile int pass)
 static void
 test_stack (void)
 {
+  char stack_buffer[SECRET_SIZE];
+  stackbuf = stack_buffer;
   int count = 0;
   int repeat;