diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2019-01-25 13:08:19 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2019-01-25 13:32:08 +0100 |
commit | b242604489934453a18c205a3594cbdc34b775e9 (patch) | |
tree | 8655a7db187b788fc1d3a0672451fd1ff2935d7d /src/cmocka.c | |
parent | 790173fc23a95d2fad35adb32a1906cf8af047ad (diff) | |
download | cmocka-b242604489934453a18c205a3594cbdc34b775e9.tar.gz cmocka-b242604489934453a18c205a3594cbdc34b775e9.tar.xz cmocka-b242604489934453a18c205a3594cbdc34b775e9.zip |
cmocka: Use calloc for allocating memory
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/cmocka.c')
-rw-r--r-- | src/cmocka.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/cmocka.c b/src/cmocka.c index ff79161..6bfc831 100644 --- a/src/cmocka.c +++ b/src/cmocka.c @@ -1897,11 +1897,11 @@ static ListNode* get_allocated_blocks_list(void) { return &global_allocated_blocks; } -static void *libc_malloc(size_t size) +static void *libc_calloc(size_t nmemb, size_t size) { -#undef malloc - return malloc(size); -#define malloc test_malloc +#undef calloc + return calloc(nmemb, size); +#define calloc test_calloc } static void libc_free(void *ptr) @@ -1941,7 +1941,7 @@ static void vcm_print_error(const char* const format, va_list args) if (cm_error_message == NULL) { /* CREATE MESSAGE */ - cm_error_message = libc_malloc(len + 1); + cm_error_message = libc_calloc(1, len + 1); if (cm_error_message == NULL) { /* TODO */ goto end; @@ -2021,6 +2021,7 @@ void* _test_calloc(const size_t number_of_elements, const size_t size, } return ptr; } +#define calloc test_calloc /* Use the real free in this function. */ @@ -2966,7 +2967,7 @@ int _cmocka_run_group_tests(const char *group_name, /* Make sure LargestIntegralType is at least the size of a pointer. */ assert_true(sizeof(LargestIntegralType) >= sizeof(void*)); - cm_tests = (struct CMUnitTestState *)libc_malloc(sizeof(struct CMUnitTestState) * num_tests); + cm_tests = libc_calloc(1, sizeof(struct CMUnitTestState) * num_tests); if (cm_tests == NULL) { return -1; } |