From ce12ea3652f40e1c42ee29bccfe91cc7889fb9b9 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 28 May 2022 12:26:52 -0700 Subject: [PATCH] bcomps: replace unchecked allocations with alloc helpers This addresses some instances where out-of-memory would go undetected, leading to a crash and/or data corruption. --- cmd/tools/bcomps.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/tools/bcomps.c b/cmd/tools/bcomps.c index b1638d6f3..3faeff8c0 100644 --- a/cmd/tools/bcomps.c +++ b/cmd/tools/bcomps.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -81,7 +82,7 @@ static char *blockName(char *gname, int d) size_t sz = strlen(gname) + 128; if (sz > bufsz) { free(buf); - buf = malloc(sz); + buf = gv_alloc(sz); } if (*gname == '%') /* anonymous graph */ @@ -107,7 +108,7 @@ static char *getName(int ng, int nb) else { if (!buf) { size_t sz = strlen(outfile) + 100; // enough to handle '__' - buf = malloc(sz); + buf = gv_alloc(sz); } if (suffix) { if (nb < 0) @@ -306,9 +307,7 @@ static void split(char *name) if (sfx) { size = sfx - name; suffix = sfx + 1; - path = malloc(size + 1); - strncpy(path, name, size); - *(path + size) = '\0'; + path = gv_strndup(name, size); } else { path = name; } -- 2.40.0