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 | 7 +++++++ tests/test-explicit_bzero.c | 8 +++++--- 2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 6ba44e7df..1caabff62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2021-07-17 Paul Eggert <egg...@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 diff --git a/tests/test-explicit_bzero.c b/tests/test-explicit_bzero.c index cdb839245..c42aba93f 100644 --- a/tests/test-explicit_bzero.c +++ b/tests/test-explicit_bzero.c @@ -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; -- 2.31.1