[HUST CSE] add forced type conversion when using 'realloc','malloc','calloc' for better readability

This commit is contained in:
zouziyu2002
2023-04-28 22:55:28 +08:00
committed by GitHub
parent 085ded8eef
commit ce4674defa
8 changed files with 16 additions and 13 deletions

View File

@@ -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 *));