summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke@hauke-m.de>2020-10-04 17:14:51 +0200
committerPetr Štetiar <ynezz@true.cz>2020-10-06 08:35:23 +0200
commit52bbc99f69ea6f67b6fe264f424dac91bde5016c (patch)
tree3f90df75a7423dddc0e7c9c678955968426e78dc
parent3fbd6c923434db61267e1331319b5b125e7838d8 (diff)
downloaduci-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.c3
-rw-r--r--libuci.c3
-rw-r--r--ucimap.c6
-rw-r--r--util.c3
4 files changed, 5 insertions, 10 deletions
diff --git a/cli.c b/cli.c
index 6ba97ea..267437d 100644
--- a/cli.c
+++ b/cli.c
@@ -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;
diff --git a/libuci.c b/libuci.c
index 786d035..ae4c964 100644
--- a/libuci.c
+++ b/libuci.c
@@ -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);
diff --git a/ucimap.c b/ucimap.c
index c46cf45..758a5ea 100644
--- a/ucimap.c
+++ b/ucimap.c
@@ -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);
}
diff --git a/util.c b/util.c
index 8572e81..61e42cd 100644
--- a/util.c
+++ b/util.c
@@ -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;
}