From ce4674defa042fcc87cc1b54b739f81edae7d797 Mon Sep 17 00:00:00 2001 From: zouziyu2002 Date: Fri, 28 Apr 2023 22:55:28 +0800 Subject: [HUST CSE] add forced type conversion when using 'realloc','malloc','calloc' for better readability --- components/libc/cplusplus/cpp11/emutls.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'components/libc') diff --git a/components/libc/cplusplus/cpp11/emutls.c b/components/libc/cplusplus/cpp11/emutls.c index bba3c4a8e0..52d1244c92 100644 --- a/components/libc/cplusplus/cpp11/emutls.c +++ b/components/libc/cplusplus/cpp11/emutls.c @@ -61,7 +61,7 @@ static __inline void *emutls_memalign_alloc(size_t align, size_t size) #else #define EXTRA_ALIGN_PTR_BYTES (align - 1 + sizeof(void *)) char *object; - if ((object = malloc(EXTRA_ALIGN_PTR_BYTES + size)) == NULL) + if ((object = (char *)malloc(EXTRA_ALIGN_PTR_BYTES + size)) == NULL) abort(); base = (void *)(((uintptr_t)(object + EXTRA_ALIGN_PTR_BYTES)) & ~(uintptr_t)(align - 1)); @@ -181,14 +181,15 @@ emutls_get_address_array(uintptr_t index) if (array == NULL) { uintptr_t new_size = emutls_new_data_array_size(index); - array = calloc(new_size + 1, sizeof(void *)); + array = (emutls_address_array *)calloc(new_size + 1, sizeof(void *)); emutls_check_array_set_size(array, new_size); } else if (index > array->size) { uintptr_t orig_size = array->size; uintptr_t new_size = emutls_new_data_array_size(index); - array = realloc(array, (new_size + 1) * sizeof(void *)); + array = (emutls_address_array *)realloc(array, (new_size + 1) * sizeof(void *)); + if (array) memset(array->data + orig_size, 0, (new_size - orig_size) * sizeof(void *)); -- cgit v1.3.1