]> granicus.if.org Git - graphviz/commitdiff
gvpr: exit on allocation failure in 'concat'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 2 Jul 2022 15:37:37 +0000 (08:37 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 4 Jul 2022 22:19:11 +0000 (15:19 -0700)
This function gracefully handled allocation failures by returning 0. Except its
caller does not check for this and assumes the returned pointer is non-null.

lib/gvpr/gvpr.c

index ef5e54ade5f850f447bacc2963cda97e3e75b836..47c8f5a3d1567e527e8b95c1e170cd80312349cf 100644 (file)
@@ -185,11 +185,7 @@ static int parseArgs(char *s, int argc, char ***argv)
 static char*
 concat (char* pfx, char* sfx)
 {
-    char *sp = malloc(strlen(pfx) + strlen(sfx) + 1);
-    if (sp == NULL) {
-       error(ERROR_ERROR, "Out of memory");
-       return 0;
-    }
+    char *sp = gv_alloc(strlen(pfx) + strlen(sfx) + 1);
     strcpy(sp, pfx);
     strcat(sp, sfx);
     return sp;