]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Use calloc(), not malloc() to allocate heap/lst elements from the (memory) heap ...
authorJames Jones <jejones3141@gmail.com>
Fri, 6 Aug 2021 16:41:52 +0000 (11:41 -0500)
committerGitHub <noreply@github.com>
Fri, 6 Aug 2021 16:41:52 +0000 (12:41 -0400)
malloc(), in the C standard and in the man page, is described as not
initializing the memory it allocates. A standard-conforming C compiler
could thus compile versions of the tests that fail fr_{heap, lst}_insert()
checks that keep an item from being inserted twice or into more than one
heap or lst with the same index displacement.

calloc() zeroes the allocated memory.

src/lib/util/heap_tests.c
src/lib/util/lst_tests.c

index 566355a13f356530ff15e960518cf9125cc124b2..4b8a3b04239edfd4c0dc361930ce59b879540953 100644 (file)
@@ -56,7 +56,7 @@ static void heap_test(int skip)
        hp = fr_heap_alloc(NULL, heap_cmp, heap_thing, heap);
        TEST_CHECK(hp != NULL);
 
-       array = malloc(sizeof(heap_thing) * HEAP_TEST_SIZE);
+       array = calloc(HEAP_TEST_SIZE, sizeof(heap_thing));
 
        /*
         *      Initialise random values
@@ -155,7 +155,7 @@ static void heap_cycle(void)
        hp = fr_heap_alloc(NULL, heap_cmp, heap_thing, heap);
        TEST_CHECK(hp != NULL);
 
-       array = malloc(sizeof(heap_thing) * HEAP_CYCLE_SIZE);
+       array = calloc(HEAP_CYCLE_SIZE, sizeof(heap_thing));
 
        /*
         *      Initialise random values
index 5dd94cbac5cef5361cd814cbf724f140fab3adf7..2aedd9801816db640aa225b17e1238d8c176c544 100644 (file)
@@ -94,7 +94,7 @@ static void lst_test(int skip)
        lst = fr_lst_alloc(NULL, heap_cmp, heap_thing, index);
        TEST_CHECK(lst != NULL);
 
-       array = malloc(sizeof(heap_thing) * LST_TEST_SIZE);
+       array = calloc(LST_TEST_SIZE, sizeof(heap_thing));
 
        /*
         *      Initialise random values