From 322ac581e306148b56d575c704787fdb55a92c6f Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Tue, 19 Sep 2023 19:11:51 +0200 Subject: [PATCH] tests: Cast malloc/calloc/realloc results to allow use as C and C++ --- expat/tests/memcheck.c | 5 +++-- expat/tests/minicheck.c | 5 +++-- expat/tests/structdata.c | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/expat/tests/memcheck.c b/expat/tests/memcheck.c index db7a5872..f5979abf 100644 --- a/expat/tests/memcheck.c +++ b/expat/tests/memcheck.c @@ -54,7 +54,8 @@ static AllocationEntry *find_allocation(const void *ptr); /* Allocate some memory and keep track of it. */ void * tracking_malloc(size_t size) { - AllocationEntry *const entry = malloc(sizeof(AllocationEntry)); + AllocationEntry *const entry + = (AllocationEntry *)malloc(sizeof(AllocationEntry)); if (entry == NULL) { printf("Allocator failure\n"); @@ -140,7 +141,7 @@ tracking_realloc(void *ptr, size_t size) { entry = find_allocation(ptr); if (entry == NULL) { printf("Attempting to realloc unallocated memory at %p\n", ptr); - entry = malloc(sizeof(AllocationEntry)); + entry = (AllocationEntry *)malloc(sizeof(AllocationEntry)); if (entry == NULL) { printf("Reallocator failure\n"); return NULL; diff --git a/expat/tests/minicheck.c b/expat/tests/minicheck.c index 219a12de..6654447c 100644 --- a/expat/tests/minicheck.c +++ b/expat/tests/minicheck.c @@ -92,7 +92,8 @@ tcase_add_test(TCase *tc, tcase_test_function test) { if (tc->allocated == tc->ntests) { int nalloc = tc->allocated + 100; size_t new_size = sizeof(tcase_test_function) * nalloc; - tcase_test_function *const new_tests = realloc(tc->tests, new_size); + tcase_test_function *const new_tests + = (tcase_test_function *)realloc(tc->tests, new_size); assert(new_tests != NULL); tc->tests = new_tests; tc->allocated = nalloc; @@ -127,7 +128,7 @@ suite_free(Suite *suite) { SRunner * srunner_create(Suite *suite) { - SRunner *const runner = calloc(1, sizeof(SRunner)); + SRunner *const runner = (SRunner *)calloc(1, sizeof(SRunner)); if (runner != NULL) { runner->suite = suite; } diff --git a/expat/tests/structdata.c b/expat/tests/structdata.c index 17e8fc6e..26596f74 100644 --- a/expat/tests/structdata.c +++ b/expat/tests/structdata.c @@ -60,7 +60,7 @@ static XML_Char * xmlstrdup(const XML_Char *s) { size_t byte_count = (xcstrlen(s) + 1) * sizeof(XML_Char); - XML_Char *const dup = malloc(byte_count); + XML_Char *const dup = (XML_Char *)malloc(byte_count); assert(dup != NULL); memcpy(dup, s, byte_count); @@ -86,8 +86,8 @@ StructData_AddItem(StructData *storage, const XML_Char *s, int data0, int data1, StructDataEntry *new_entries; storage->max_count += STRUCT_EXTENSION_COUNT; - new_entries = realloc(storage->entries, - storage->max_count * sizeof(StructDataEntry)); + new_entries = (StructDataEntry *)realloc( + storage->entries, storage->max_count * sizeof(StructDataEntry)); assert(new_entries != NULL); storage->entries = new_entries; }