浏览代码

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

zouziyu2002 2 年之前
父节点
当前提交
ce4674defa

+ 1 - 1
bsp/loongson/ls2kdev/drivers/ata/dwc_ahsata.c

@@ -995,7 +995,7 @@ static int ahci_init_one(int pdev)
     int rc;
     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)
         return -ENOMEM;
 

+ 1 - 1
bsp/simulator/drivers/board.c

@@ -23,7 +23,7 @@
 rt_uint8_t *rt_hw_sram_init(void)
 {
     rt_uint8_t *heap;
-    heap = malloc(RT_HEAP_SIZE);
+    heap = (rt_uint8_t *)malloc(RT_HEAP_SIZE);
     if (heap == RT_NULL)
     {
         rt_kprintf("there is no memory in pc.");

+ 1 - 1
bsp/simulator/drivers/dfs_win32.c

@@ -191,7 +191,7 @@ static int dfs_win32_open(struct dfs_file *file)
         len = strlen(wdirp->finddata.name) + 1;
         wdirp->handle = handle;
         //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 += len;
         rt_strncpy(wdirp->curr, wdirp->finddata.name, len);

+ 1 - 1
components/drivers/fdt/src/dtb_base.c

@@ -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
components/drivers/fdt/src/dtb_get.c

@@ -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
components/drivers/fdt/src/dtb_load.c

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

+ 1 - 1
examples/libc/ex4.c

@@ -58,7 +58,7 @@ char * str_accumulate(const char * s)
   accu = (char *) pthread_getspecific(str_key);
   /* It's initially NULL, meaning that we must allocate the buffer first. */
   if (accu == NULL) {
-    accu = malloc(1024);
+    accu = (char *)malloc(1024);
     if (accu == NULL) return NULL;
     accu[0] = 0;
     /* Store the buffer pointer in the thread-specific data. */