From: Bruno Haible Date: Sun, 29 Aug 2021 16:54:54 +0000 (+0200) Subject: explicit_bzero test: Fix test failure due to GCC optimizations. X-Git-Tag: v1.0~2630 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=a55152ea2eb061403ab128cd7a63772753e83cd0;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 04ddcd1f3f..ce9a2b3664 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2021-08-29 Bruno Haible + + 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 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 + base32, base64: fix broken tests Problem reported by Bruno Haible in: https://lists.gnu.org/r/bug-gnulib/2021-08/msg00170.html diff --git a/tests/test-explicit_bzero.c b/tests/test-explicit_bzero.c index 14f0ead2b7..15a2526983 100644 --- a/tests/test-explicit_bzero.c +++ b/tests/test-explicit_bzero.c @@ -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