From 172e67fc049fe5e00edc7054fb3385678bdd4ff2 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 16 Jul 2022 10:20:05 -0700 Subject: [PATCH] common mkDirlist: switch to cgraph allocation helpers These have the advantage of zeroing newly allocated memory, leaving the caller one fewer thing to worry about. --- lib/common/utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/common/utils.c b/lib/common/utils.c index ec1fb2cd9..0cfe3a788 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -9,6 +9,7 @@ *************************************************************************/ #include +#include #include #include #include @@ -323,16 +324,15 @@ char *Fgets(FILE * fp) static strview_t *mkDirlist(const char *list, size_t *maxdirlen) { size_t cnt = 0; - strview_t *dirs = NULL; + strview_t *dirs = gv_calloc(1, sizeof(strview_t)); size_t maxlen = 0; for (tok_t t = tok(list, PATHSEP); !tok_end(&t); tok_next(&t)) { strview_t dir = tok_get(&t); - dirs = ALLOC(cnt + 2, dirs, strview_t); + dirs = gv_recalloc(dirs, cnt + 1, cnt + 2, sizeof(strview_t)); dirs[cnt++] = dir; maxlen = MAX(maxlen, dir.size); } - dirs[cnt] = (strview_t){0}; *maxdirlen = maxlen; return dirs; } -- 2.40.0