[v3,3/3] cfgfile: use calloc

Message ID 20190718171812.3209-4-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series cfgfile: cleanup patches |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Stephen Hemminger July 18, 2019, 5:18 p.m. UTC
  Better to use calloc when allocating arrays.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_cfgfile/rte_cfgfile.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
  

Patch

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index 388415147930..9049fd9c2319 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -281,17 +281,16 @@  rte_cfgfile_create(int flags)
 	cfg->num_sections = 0;
 
 	/* allocate first batch of sections and entries */
-	cfg->sections = malloc(sizeof(struct rte_cfgfile_section) *
-			CFG_ALLOC_SECTION_BATCH);
-
+	cfg->sections = calloc(CFG_ALLOC_SECTION_BATCH,
+			       sizeof(struct rte_cfgfile_section));
 	if (cfg->sections == NULL)
 		goto error1;
 
 	cfg->allocated_sections = CFG_ALLOC_SECTION_BATCH;
 
 	for (i = 0; i < CFG_ALLOC_SECTION_BATCH; i++) {
-		cfg->sections[i].entries = malloc(sizeof(
-			struct rte_cfgfile_entry) * CFG_ALLOC_ENTRY_BATCH);
+		cfg->sections[i].entries = calloc(CFG_ALLOC_ENTRY_BATCH,
+					  sizeof(struct rte_cfgfile_entry));
 
 		if (cfg->sections[i].entries == NULL)
 			goto error1;