From 7c028e224978e1d5a4f207cc42b9eb58d81897dd Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 23 Aug 2019 01:33:50 +0200 Subject: Some simple search/replace cases for allocation This commit exchanges some malloc(x + y * z) patterns that can be found with a simple git grep and are obvious for the new wrappers. Signed-off-by: David Oberhollenzer --- lib/fstree/fstree_from_dir.c | 4 ++-- lib/fstree/gen_inode_table.c | 4 +++- lib/fstree/mknode.c | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/fstree') diff --git a/lib/fstree/fstree_from_dir.c b/lib/fstree/fstree_from_dir.c index ae8cac9..9aab5df 100644 --- a/lib/fstree/fstree_from_dir.c +++ b/lib/fstree/fstree_from_dir.c @@ -90,7 +90,7 @@ static int populate_xattr(fstree_t *fs, tree_node_t *node) goto fail; if (vallen > 0) { - value = calloc(1, vallen + 1); + value = alloc_string(vallen); if (value == NULL) { perror("xattr value buffer"); goto fail; @@ -163,7 +163,7 @@ static int populate_dir(fstree_t *fs, tree_node_t *root, dev_t devstart, continue; if (S_ISLNK(sb.st_mode)) { - extra = calloc(1, sb.st_size + 1); + extra = alloc_string(sb.st_size); if (extra == NULL) goto fail_rdlink; diff --git a/lib/fstree/gen_inode_table.c b/lib/fstree/gen_inode_table.c index 98294fa..04f68da 100644 --- a/lib/fstree/gen_inode_table.c +++ b/lib/fstree/gen_inode_table.c @@ -7,6 +7,7 @@ #include "config.h" #include "fstree.h" +#include "util.h" #include #include @@ -60,7 +61,8 @@ int fstree_gen_inode_table(fstree_t *fs) size_t inum = 2; fs->inode_tbl_size = count_nodes(fs->root) + 2; - fs->inode_table = calloc(sizeof(tree_node_t *), fs->inode_tbl_size); + fs->inode_table = alloc_array(sizeof(tree_node_t *), + fs->inode_tbl_size); if (fs->inode_table == NULL) { perror("allocating inode table"); diff --git a/lib/fstree/mknode.c b/lib/fstree/mknode.c index 954771f..9132458 100644 --- a/lib/fstree/mknode.c +++ b/lib/fstree/mknode.c @@ -7,6 +7,7 @@ #include "config.h" #include "fstree.h" +#include "util.h" #include #include -- cgit v1.2.3