]> granicus.if.org Git - libevent/commitdiff
test: enable allocator_may_return_null=1 for calloc with ENOMEM test
authorAzat Khuzhin <azat@libevent.org>
Sun, 12 Feb 2023 16:05:20 +0000 (17:05 +0100)
committerAzat Khuzhin <azat@libevent.org>
Sun, 12 Feb 2023 20:55:40 +0000 (21:55 +0100)
.github/workflows/build.yml
test/regress_util.c

index ad3a4d2b3f34dfccc6217a4a5a66ee45bf8fe3f5..6620157139aed29c1c12e6052f8157016b0a4676 100644 (file)
@@ -134,8 +134,10 @@ jobs:
             export CTEST_PARALLEL_LEVEL=$JOBS
             export CTEST_OUTPUT_ON_FAILURE=1
 
-            export TSAN_OPTIONS=suppressions=$PWD/extra/tsan.supp
+            # Enable allocator_may_return_null for test_event_calloc_enomem
+            export TSAN_OPTIONS=suppressions=$PWD/extra/tsan.supp:allocator_may_return_null=1
             export LSAN_OPTIONS=suppressions=$PWD/extra/lsan.supp
+            export ASAN_OPTIONS=allocator_may_return_null=1
 
             if [ "${{ matrix.EVENT_MATRIX }}" == "DIST" ]; then
               cd dist
index 63222516a5ed36bc4d70364ab73d73a3c81d467f..430b3cdd7600248d3cbd8884cb457a8ca1dcc29f 100644 (file)
@@ -1310,6 +1310,17 @@ test_event_calloc(void *arg)
        mm_free(p);
        p = NULL;
 
+ end:
+       errno = 0;
+       if (p)
+               mm_free(p);
+}
+
+static void
+test_event_calloc_enomem(void *arg)
+{
+       void *p = NULL;
+
        /* mm_calloc() should set errno = ENOMEM and return NULL
         * in case of potential overflow. */
        errno = 0;
@@ -1318,6 +1329,7 @@ test_event_calloc(void *arg)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Walloc-size-larger-than="
 #endif
+       /* Requires allocator_may_return_null=1 for sanitizers */
        p = mm_calloc(EV_SIZE_MAX, EV_SIZE_MAX);
 #if defined(__clang__)
 #elif defined(__GNUC__)
@@ -1327,11 +1339,7 @@ test_event_calloc(void *arg)
        tt_int_op(errno, ==, ENOMEM);
 
  end:
-       errno = 0;
-       if (p)
-               mm_free(p);
-
-       return;
+       ;
 }
 
 static void
@@ -1857,6 +1865,7 @@ struct testcase_t util_testcases[] = {
 #endif
        { "mm_malloc", test_event_malloc, 0, NULL, NULL },
        { "mm_calloc", test_event_calloc, 0, NULL, NULL },
+       { "mm_calloc_enomem", test_event_calloc_enomem, 0, NULL, NULL },
        { "mm_strdup", test_event_strdup, 0, NULL, NULL },
        { "usleep", test_evutil_usleep, TT_RETRIABLE, NULL, NULL },
        { "monotonic_res", test_evutil_monotonic_res, 0, &basic_setup, (void*)"" },