]> granicus.if.org Git - graphviz/commitdiff
pathplan Pobspath: replace an unchecked array 'malloc' with 'gv_calloc'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 30 Jul 2022 16:50:18 +0000 (09:50 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 5 Aug 2022 13:52:10 +0000 (06:52 -0700)
This function has no way of reporting failure to the caller. So this turns an
allocation failure from a messy crash into a more graceful exit.

lib/pathplan/cvt.c

index 27ef7b29bc6fd37d163b86aa66d97b003aaa505a..e7e7022d43e3a838c30b5952979db28ec2dcc072 100644 (file)
@@ -11,6 +11,7 @@
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <cgraph/alloc.h>
 #include <cgraph/likely.h>
 #include <limits.h>
 #include <pathplan/vis.h>
@@ -128,7 +129,7 @@ int Pobspath(vconfig_t * config, Ppoint_t p0, int poly0, Ppoint_t p1,
     for (i = dad[config->N]; i != config->N + 1; i = dad[i])
        opn++;
     opn++;
-    ops = malloc(opn * sizeof(Ppoint_t));
+    ops = gv_calloc(opn, sizeof(Ppoint_t));
 
     size_t j = opn - 1;
     ops[j--] = p1;