tests/util_allocator.c

changeset 985
68754c7de906
parent 890
54565fd74e74
--- a/tests/util_allocator.c	Thu Nov 07 20:22:56 2024 +0100
+++ b/tests/util_allocator.c	Thu Nov 07 22:46:58 2024 +0100
@@ -29,6 +29,11 @@
 #include "util_allocator.h"
 #include "cx/test.h"
 
+#if !defined(__clang__) && __GNUC__ > 11
+// this utility is explicitly designed to track UAF
+#pragma GCC diagnostic ignored "-Wuse-after-free"
+#endif
+
 static void cx_testing_allocator_track(CxTestingAllocator *alloc, void *ptr) {
     for (size_t i = 0; i < alloc->tracked_count; i++) {
         if (alloc->tracked[i] == ptr) return; // is already tracked
@@ -83,16 +88,9 @@
             data->alloc_failed++;
         } else {
             data->free_total++;
-#if !defined(__clang__) && __GNUC__ > 11
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wuse-after-free"
-#endif
             if (!cx_testing_allocator_untrack(data, mem)) {
                 data->free_failed++;
             }
-#if !defined(__clang__) && __GNUC__ > 11
-#pragma GCC diagnostic pop
-#endif
             cx_testing_allocator_track(data, ptr);
         }
         return ptr;

mercurial