[HUST CSE] add forced type conversion when using 'realloc','malloc','calloc' for better readability
This commit is contained in:
parent
085ded8eef
commit
ce4674defa
|
@ -995,7 +995,7 @@ static int ahci_init_one(int pdev)
|
||||||
int rc;
|
int rc;
|
||||||
struct ahci_uc_priv *uc_priv = NULL;
|
struct ahci_uc_priv *uc_priv = NULL;
|
||||||
|
|
||||||
uc_priv = malloc(sizeof(struct ahci_uc_priv));
|
uc_priv = (struct ahci_uc_priv *)malloc(sizeof(struct ahci_uc_priv));
|
||||||
if (!uc_priv)
|
if (!uc_priv)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
rt_uint8_t *rt_hw_sram_init(void)
|
rt_uint8_t *rt_hw_sram_init(void)
|
||||||
{
|
{
|
||||||
rt_uint8_t *heap;
|
rt_uint8_t *heap;
|
||||||
heap = malloc(RT_HEAP_SIZE);
|
heap = (rt_uint8_t *)malloc(RT_HEAP_SIZE);
|
||||||
if (heap == RT_NULL)
|
if (heap == RT_NULL)
|
||||||
{
|
{
|
||||||
rt_kprintf("there is no memory in pc.");
|
rt_kprintf("there is no memory in pc.");
|
||||||
|
|
|
@ -191,7 +191,7 @@ static int dfs_win32_open(struct dfs_file *file)
|
||||||
len = strlen(wdirp->finddata.name) + 1;
|
len = strlen(wdirp->finddata.name) + 1;
|
||||||
wdirp->handle = handle;
|
wdirp->handle = handle;
|
||||||
//wdirp->nfiles = 1;
|
//wdirp->nfiles = 1;
|
||||||
wdirp->start = malloc(len); //not rt_malloc!
|
wdirp->start = (char *)malloc(len); //not rt_malloc!
|
||||||
wdirp->end = wdirp->curr = wdirp->start;
|
wdirp->end = wdirp->curr = wdirp->start;
|
||||||
wdirp->end += len;
|
wdirp->end += len;
|
||||||
rt_strncpy(wdirp->curr, wdirp->finddata.name, len);
|
rt_strncpy(wdirp->curr, wdirp->finddata.name, len);
|
||||||
|
|
|
@ -401,7 +401,7 @@ int dtb_node_write_prop(const struct dtb_node *node, const char *propname, int l
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
/* Property does not exist -> append new property */
|
/* Property does not exist -> append new property */
|
||||||
new = malloc(sizeof(struct dtb_property));
|
new = (struct dtb_property *)malloc(sizeof(struct dtb_property));
|
||||||
if (!new)
|
if (!new)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,8 @@ struct dtb_node *dtb_node_get_dtb_list(void *fdt)
|
||||||
|
|
||||||
if (paths_buf.ptr == NULL)
|
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)
|
if (paths_buf.ptr == NULL)
|
||||||
{
|
{
|
||||||
fdt_exec_status = FDT_RET_NO_MEMORY;
|
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, "/");
|
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;
|
fdt_exec_status = FDT_RET_NO_MEMORY;
|
||||||
goto fail;
|
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);
|
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 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)
|
if (dtb_node_head->header->memreserve == NULL)
|
||||||
{
|
{
|
||||||
fdt_exec_status = FDT_RET_NO_MEMORY;
|
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_sz = strlen(pathname) + 1;
|
||||||
pathname_clone = malloc(pathname_sz);
|
pathname_clone = (char *)malloc(pathname_sz);
|
||||||
if (pathname_clone == NULL)
|
if (pathname_clone == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -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);
|
size_t dtb_sz = fdt_totalsize(dtb_ptr);
|
||||||
if (dtb_sz > 0)
|
if (dtb_sz > 0)
|
||||||
{
|
{
|
||||||
if ((fdt = malloc(dtb_sz)) != NULL)
|
if ((fdt = (size_t *)malloc(dtb_sz)) != NULL)
|
||||||
{
|
{
|
||||||
memcpy(fdt, dtb_ptr, dtb_sz);
|
memcpy(fdt, dtb_ptr, dtb_sz);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ static __inline void *emutls_memalign_alloc(size_t align, size_t size)
|
||||||
#else
|
#else
|
||||||
#define EXTRA_ALIGN_PTR_BYTES (align - 1 + sizeof(void *))
|
#define EXTRA_ALIGN_PTR_BYTES (align - 1 + sizeof(void *))
|
||||||
char *object;
|
char *object;
|
||||||
if ((object = malloc(EXTRA_ALIGN_PTR_BYTES + size)) == NULL)
|
if ((object = (char *)malloc(EXTRA_ALIGN_PTR_BYTES + size)) == NULL)
|
||||||
abort();
|
abort();
|
||||||
base = (void *)(((uintptr_t)(object + EXTRA_ALIGN_PTR_BYTES)) & ~(uintptr_t)(align - 1));
|
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)
|
if (array == NULL)
|
||||||
{
|
{
|
||||||
uintptr_t new_size = emutls_new_data_array_size(index);
|
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);
|
emutls_check_array_set_size(array, new_size);
|
||||||
}
|
}
|
||||||
else if (index > array->size)
|
else if (index > array->size)
|
||||||
{
|
{
|
||||||
uintptr_t orig_size = array->size;
|
uintptr_t orig_size = array->size;
|
||||||
uintptr_t new_size = emutls_new_data_array_size(index);
|
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)
|
if (array)
|
||||||
memset(array->data + orig_size, 0,
|
memset(array->data + orig_size, 0,
|
||||||
(new_size - orig_size) * sizeof(void *));
|
(new_size - orig_size) * sizeof(void *));
|
||||||
|
|
|
@ -58,7 +58,7 @@ char * str_accumulate(const char * s)
|
||||||
accu = (char *) pthread_getspecific(str_key);
|
accu = (char *) pthread_getspecific(str_key);
|
||||||
/* It's initially NULL, meaning that we must allocate the buffer first. */
|
/* It's initially NULL, meaning that we must allocate the buffer first. */
|
||||||
if (accu == NULL) {
|
if (accu == NULL) {
|
||||||
accu = malloc(1024);
|
accu = (char *)malloc(1024);
|
||||||
if (accu == NULL) return NULL;
|
if (accu == NULL) return NULL;
|
||||||
accu[0] = 0;
|
accu[0] = 0;
|
||||||
/* Store the buffer pointer in the thread-specific data. */
|
/* Store the buffer pointer in the thread-specific data. */
|
||||||
|
|
Loading…
Reference in New Issue