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

This commit is contained in:
zouziyu2002
2023-04-28 15:55:28 +01:00
committed by GitHub
parent 085ded8eef
commit ce4674defa
8 changed files with 16 additions and 13 deletions
+1 -1
View File
@@ -401,7 +401,7 @@ int dtb_node_write_prop(const struct dtb_node *node, const char *propname, int l
return -ENOENT;
/* Property does not exist -> append new property */
new = malloc(sizeof(struct dtb_property));
new = (struct dtb_property *)malloc(sizeof(struct dtb_property));
if (!new)
return -ENOMEM;
+6 -4
View File
@@ -176,7 +176,8 @@ struct dtb_node *dtb_node_get_dtb_list(void *fdt)
if (paths_buf.ptr == NULL)
{
paths_buf.ptr = malloc(FDT_DTB_ALL_NODES_PATH_SIZE);
paths_buf.ptr = (char *)malloc(FDT_DTB_ALL_NODES_PATH_SIZE);
if (paths_buf.ptr == NULL)
{
fdt_exec_status = FDT_RET_NO_MEMORY;
@@ -188,7 +189,8 @@ struct dtb_node *dtb_node_get_dtb_list(void *fdt)
root_off = fdt_path_offset(fdt, "/");
if ((dtb_node_head->header = malloc(sizeof(struct dtb_header))) == NULL)
if ((dtb_node_head->header = (struct dtb_header *)malloc(sizeof(struct dtb_header))) == NULL)
{
fdt_exec_status = FDT_RET_NO_MEMORY;
goto fail;
@@ -206,7 +208,7 @@ struct dtb_node *dtb_node_get_dtb_list(void *fdt)
uint32_t off_mem_rsvmap = fdt_off_mem_rsvmap(fdt);
struct fdt_reserve_entry *rsvmap = (struct fdt_reserve_entry *)((char *)fdt + off_mem_rsvmap);
((struct dtb_header *)dtb_node_head->header)->memreserve = malloc(sizeof(struct dtb_memreserve) * memreserve_sz);
((struct dtb_header *)dtb_node_head->header)->memreserve = (struct dtb_memreserve *)malloc(sizeof(struct dtb_memreserve) * memreserve_sz);
if (dtb_node_head->header->memreserve == NULL)
{
fdt_exec_status = FDT_RET_NO_MEMORY;
@@ -560,7 +562,7 @@ struct dtb_node *dtb_node_get_dtb_node_by_path(struct dtb_node *dtb_node, const
}
pathname_sz = strlen(pathname) + 1;
pathname_clone = malloc(pathname_sz);
pathname_clone = (char *)malloc(pathname_sz);
if (pathname_clone == NULL)
{
return NULL;
+1 -1
View File
@@ -87,7 +87,7 @@ void *dtb_node_load_from_memory(void *dtb_ptr, rt_bool_t is_clone)
size_t dtb_sz = fdt_totalsize(dtb_ptr);
if (dtb_sz > 0)
{
if ((fdt = malloc(dtb_sz)) != NULL)
if ((fdt = (size_t *)malloc(dtb_sz)) != NULL)
{
memcpy(fdt, dtb_ptr, dtb_sz);
}
+4 -3
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 *));