bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* [PATCH 1/2] explicit_bzero-tests: pacify GCC
@ 2021-07-18  4:56 Paul Eggert
  2021-07-18  4:56 ` [PATCH 2/2] memrchr-tests: " Paul Eggert
  2021-07-18  9:12 ` [PATCH 1/2] explicit_bzero-tests: " Bruno Haible
  0 siblings, 2 replies; 7+ messages in thread
From: Paul Eggert @ 2021-07-18  4:56 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Paul Eggert

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  <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
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



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-07-19  0:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-18  4:56 [PATCH 1/2] explicit_bzero-tests: pacify GCC Paul Eggert
2021-07-18  4:56 ` [PATCH 2/2] memrchr-tests: " Paul Eggert
2021-07-18  9:12 ` [PATCH 1/2] explicit_bzero-tests: " Bruno Haible
2021-07-18 19:14   ` Paul Eggert
2021-07-18 22:23     ` Bruno Haible
2021-07-18 23:17       ` Paul Eggert
2021-07-19  0:37         ` Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).