]> granicus.if.org Git - graphviz/commitdiff
gvcolor color: fix unchecked allocation failure
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 28 Aug 2022 16:04:12 +0000 (09:04 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 30 Aug 2022 04:01:31 +0000 (21:01 -0700)
cmd/tools/gvcolor.c

index e0a1d872ccbc9ba76058d8777ed68b3363581448..1cf5fc2d42fb97c0904295bcdd395725063bd83b 100644 (file)
@@ -23,6 +23,7 @@
 #define        NC      3               /* size of HSB color vector */
 
 #include <assert.h>
+#include <cgraph/alloc.h>
 #include <cgraph/cgraph.h>
 #include <cgraph/exit.h>
 #include <math.h>
@@ -147,7 +148,7 @@ static void color(Agraph_t * g)
     nn = agnnodes(g);
     assert(nn >= 0);
     size_t nnodes = (size_t)nn;
-    nlist = malloc(nnodes * sizeof(Agnode_t *));
+    nlist = gv_calloc(nnodes, sizeof(Agnode_t *));
     size_t i = 0;
     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
        nlist[i++] = n;