From 7383e7cf33edb331e0ec64ba2c1f67b297856dc8 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Fri, 1 Apr 2016 17:02:13 +0200 Subject: [PATCH] liboconfig: malloc + memset -> calloc --- src/liboconfig/oconfig.c | 5 ++--- src/liboconfig/parser.y | 6 ++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/liboconfig/oconfig.c b/src/liboconfig/oconfig.c index 48f0b25f..b4b82442 100644 --- a/src/liboconfig/oconfig.c +++ b/src/liboconfig/oconfig.c @@ -106,13 +106,12 @@ oconfig_item_t *oconfig_clone (const oconfig_item_t *ci_orig) { oconfig_item_t *ci_copy; - ci_copy = malloc (sizeof (*ci_copy)); + ci_copy = calloc (1, sizeof (*ci_copy)); if (ci_copy == NULL) { - fprintf (stderr, "malloc failed.\n"); + fprintf (stderr, "calloc failed.\n"); return (NULL); } - memset (ci_copy, 0, sizeof (*ci_copy)); ci_copy->values = NULL; ci_copy->parent = NULL; ci_copy->children = NULL; diff --git a/src/liboconfig/parser.y b/src/liboconfig/parser.y index 57e9ddff..1eb7aece 100644 --- a/src/liboconfig/parser.y +++ b/src/liboconfig/parser.y @@ -208,15 +208,13 @@ statement_list: entire_file: statement_list { - ci_root = malloc (sizeof (*ci_root)); - memset (ci_root, '\0', sizeof (*ci_root)); + ci_root = calloc (1, sizeof (*ci_root)); ci_root->children = $1.statement; ci_root->children_num = $1.statement_num; } | /* epsilon */ { - ci_root = malloc (sizeof (*ci_root)); - memset (ci_root, '\0', sizeof (*ci_root)); + ci_root = calloc (1, sizeof (*ci_root)); ci_root->children = NULL; ci_root->children_num = 0; } -- 2.30.2