From c094c232eb3246154265bb035182f92fe1b17ab8 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Tue, 25 Jan 2022 15:39:38 -0700 Subject: Avoid -Wuse-after-free in tests [BZ #26779]. Reviewed-by: Carlos O'Donell --- malloc/tst-malloc-backtrace.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'malloc/tst-malloc-backtrace.c') diff --git a/malloc/tst-malloc-backtrace.c b/malloc/tst-malloc-backtrace.c index ea66da23ef..65e1a1ffbc 100644 --- a/malloc/tst-malloc-backtrace.c +++ b/malloc/tst-malloc-backtrace.c @@ -20,6 +20,7 @@ #include #include +#include #define SIZE 4096 @@ -29,7 +30,15 @@ __attribute__((noinline)) call_free (void *ptr) { free (ptr); +#if __GNUC_PREREQ (12, 0) + /* Ignore a valid warning about using a pointer made indeterminate + by a prior call to free(). */ + DIAG_IGNORE_NEEDS_COMMENT (12, "-Wuse-after-free"); +#endif *(size_t *)(ptr - sizeof (size_t)) = 1; +#if __GNUC_PREREQ (12, 0) + DIAG_POP_NEEDS_COMMENT; +#endif } int -- cgit v1.2.3