]> granicus.if.org Git - graphviz/commitdiff
refactor any N_GNEW calls that can tolerate allocation failure to calloc
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 15 Jun 2020 23:43:30 +0000 (16:43 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 16 Jun 2020 01:45:30 +0000 (18:45 -0700)
We are about to change the N_GNEW wrapper to exit on failure, so this preserves
the semantics of allowing these few locations to handle allocation failure
locally.

lib/common/routespl.c
lib/pack/ccomps.c
lib/sfdpgen/post_process.c

index d993ca008decff77369a6effb367564eb18db921..1acdf6aa4a4cdd12339e92e0b2b141858e9ebdd5 100644 (file)
@@ -16,6 +16,7 @@
 #include "render.h"
 #include "pathplan.h"
 #include <setjmp.h>
+#include <stdlib.h>
 
 #ifdef UNUSED
 static box *bs = NULL;
@@ -288,7 +289,7 @@ int
 routesplinesinit()
 {
     if (++routeinit > 1) return 0;
-    if (!(ps = N_GNEW(PINC, pointf))) {
+    if (!(ps = calloc(PINC, sizeof(pointf)))) {
        agerr(AGERR, "routesplinesinit: cannot allocate ps\n");
        return 1;
     }
index 196239ed42e940d420e8c7685dbed97c9ebd47a0..6b295298fc08cf5529cf363650501d118dfa2e52 100644 (file)
@@ -82,7 +82,7 @@ static void push(stk_t* sp, Agnode_t * np)
            }
            bp->prev = sp->curblk;
            bp->next = NULL;
-           bp->data = N_GNEW(BIGBUF, Agnode_t *);
+           bp->data = calloc(BIGBUF, sizeof(Agnode_t *));
            if (bp->data == 0) {
                agerr(AGERR, "gc: Out of memory\n");
                longjmp(jbuf, 1);
index 0e8aa8a4307d71c50a76ee207fba1bdcdb74f4ab..4e6669cc2d138f03d7e567f9c06d565213ee7b24 100644 (file)
@@ -16,6 +16,7 @@
 #include <time.h>
 #include <string.h>
 #include <math.h>
+#include <stdlib.h>
 
 #include "types.h"
 #include "memory.h"
@@ -819,11 +820,11 @@ real StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, r
 
   Lwdd = SparseMatrix_copy(Lwd);
   m = Lw->m;
-  x0 = N_GNEW(dim*m,real);
+  x0 = calloc(dim*m, sizeof(real));
   if (!x0) goto RETURN;
 
   memcpy(x0, x, sizeof(real)*dim*m);
-  y = N_GNEW(dim*m,real);
+  y = calloc(dim*m, sizeof(real));
   if (!y) goto RETURN;
 
   id = Lwd->ia; jd = Lwd->ja;