diff options
author | Hauke Mehrtens <hauke@hauke-m.de> | 2020-10-04 17:14:51 +0200 |
---|---|---|
committer | Petr Štetiar <ynezz@true.cz> | 2020-10-06 08:35:23 +0200 |
commit | 52bbc99f69ea6f67b6fe264f424dac91bde5016c (patch) | |
tree | 3f90df75a7423dddc0e7c9c678955968426e78dc | |
parent | 3fbd6c923434db61267e1331319b5b125e7838d8 (diff) | |
download | uci-52bbc99f69ea6f67b6fe264f424dac91bde5016c.tar.gz |
Replace malloc() + memset() with calloc()
Instead of manually clearing the memory with memset() use calloc().
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
-rw-r--r-- | cli.c | 3 | ||||
-rw-r--r-- | libuci.c | 3 | ||||
-rw-r--r-- | ucimap.c | 6 | ||||
-rw-r--r-- | util.c | 3 |
4 files changed, 5 insertions, 10 deletions
@@ -100,10 +100,9 @@ uci_lookup_section_ref(struct uci_section *s) ti = ti->next; } if (!ti) { - ti = malloc(sizeof(struct uci_type_list)); + ti = calloc(1, sizeof(struct uci_type_list)); if (!ti) return NULL; - memset(ti, 0, sizeof(struct uci_type_list)); ti->next = type_list; type_list = ti; ti->name = s->type; @@ -48,11 +48,10 @@ struct uci_context *uci_alloc_context(void) { struct uci_context *ctx; - ctx = (struct uci_context *) malloc(sizeof(struct uci_context)); + ctx = (struct uci_context *) calloc(1, sizeof(struct uci_context)); if (!ctx) return NULL; - memset(ctx, 0, sizeof(struct uci_context)); uci_list_init(&ctx->root); uci_list_init(&ctx->delta_path); uci_list_init(&ctx->backends); @@ -661,11 +661,10 @@ ucimap_parse_section(struct uci_map *map, struct uci_sectionmap *sm, struct ucim size = sizeof(struct ucimap_list) + n_elements * sizeof(union ucimap_data); - data->list = malloc(size); + data->list = calloc(1, size); if (!data->list) goto error_mem; - memset(data->list, 0, size); data->list->size = n_elements; } else { ucimap_count_alloc(om, &n_alloc, &n_alloc_custom); @@ -897,10 +896,9 @@ ucimap_parse(struct uci_map *map, struct uci_package *pkg) continue; memset(sd, 0, sizeof(struct ucimap_section_data)); } else { - sd = malloc(sm->alloc_len); + sd = calloc(1, sm->alloc_len); if (!sd) continue; - memset(sd, 0, sm->alloc_len); sd = ucimap_ptr_section(sm, sd); } @@ -36,10 +36,9 @@ __private void *uci_malloc(struct uci_context *ctx, size_t size) { void *ptr; - ptr = malloc(size); + ptr = calloc(1, size); if (!ptr) UCI_THROW(ctx, UCI_ERR_MEM); - memset(ptr, 0, size); return ptr; } |