From 0ff241a1ea34eab454fb8fb27d0a39d63ceea709 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Sat, 25 Jun 2022 14:29:23 +0200 Subject: [PATCH] Remove largely useless bit of test log to silence GCC 12 GCC 12 emits a warning because it thinks `buffer1` is used after having been freed. The code is correct C because we're only using the value of `(uintptr_t)buffer1`, not `buffer1`. However, we aren't using the value for anything useful: it doesn't really matter if an alloc-free-alloc sequence returns the same address twice. So don't print that bit of information, and this way we don't need to save the old address. Fixes #5974. Signed-off-by: Gilles Peskine --- ChangeLog.d/selftest-gcc12.txt | 2 ++ programs/test/selftest.c | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) create mode 100644 ChangeLog.d/selftest-gcc12.txt diff --git a/ChangeLog.d/selftest-gcc12.txt b/ChangeLog.d/selftest-gcc12.txt new file mode 100644 index 000000000..aafa2566a --- /dev/null +++ b/ChangeLog.d/selftest-gcc12.txt @@ -0,0 +1,2 @@ +Bugfix + * Silence a warning from GCC 12 in the selftest program. Fixes #5974. diff --git a/programs/test/selftest.c b/programs/test/selftest.c index a314bd22d..ab337a21f 100644 --- a/programs/test/selftest.c +++ b/programs/test/selftest.c @@ -84,7 +84,6 @@ static int calloc_self_test( int verbose ) void *empty2 = mbedtls_calloc( 0, 1 ); void *buffer1 = mbedtls_calloc( 1, 1 ); void *buffer2 = mbedtls_calloc( 1, 1 ); - uintptr_t old_buffer1; if( empty1 == NULL && empty2 == NULL ) { @@ -126,7 +125,6 @@ static int calloc_self_test( int verbose ) mbedtls_printf( " CALLOC(1): passed\n" ); } - old_buffer1 = (uintptr_t) buffer1; mbedtls_free( buffer1 ); buffer1 = mbedtls_calloc( 1, 1 ); if( buffer1 == NULL ) @@ -138,9 +136,7 @@ static int calloc_self_test( int verbose ) else { if( verbose ) - mbedtls_printf( " CALLOC(1 again): passed (%s address)\n", - (uintptr_t) old_buffer1 == (uintptr_t) buffer1 ? - "same" : "different" ); + mbedtls_printf( " CALLOC(1 again): passed\n" ); } if( verbose )