tests: Silence an unused-but-set-variable warning with GCC 16

Compiling tests with GCC 16 results into this warning:

    gcc -shared -o libmallocintercept.so -fpic -std=gnu99 -Wall -DFAKE_STAT -Werror -Wextra  -U_FILE_OFFSET_BITS -U_TIME_BITS libmallocintercept.c
    libmallocintercept.c: In function ‘free’:
    libmallocintercept.c:79:12: error: variable ‘ptr2’ set but not used [-Werror=unused-but-set-variable=]
       79 |   long int ptr2 = (long int) ptr; ptr2 -= (long int) ptr;
	  |            ^~~~
    cc1: all warnings being treated as errors

The ptr2 variable was added in the past to silence compiler warnings,
probably for the very same reason (commits
75cbe8e507 and
2bfbe19f71). GCC 16 is smarter and
discovers that the ptr2 variables is not needed.

This patch changes the work around to "(void) unused_variable;" idiom
recommended by GCC manual and already used in print_msg().
This commit is contained in:
Petr Písař
2026-01-06 10:18:50 +01:00
parent 1e931cb4cd
commit 712733e5f0

View File

@@ -76,7 +76,7 @@ void *malloc(size_t size) {
} }
void free(void *ptr) { void free(void *ptr) {
long int ptr2 = (long int) ptr; ptr2 -= (long int) ptr; (void) ptr; /* unused */
print_msg("Called free() on from libmallocintercept..."); print_msg("Called free() on from libmallocintercept...");
poke_faketime(); poke_faketime();
print_msg("successfully\n"); print_msg("successfully\n");