]> granicus.if.org Git - graphviz/commitdiff
Revert "Merge branch 'master' of ssh://gitlab.com/graphviz/graphviz into 7ca60983...
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 22 Jun 2020 14:58:52 +0000 (07:58 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 22 Jun 2020 14:58:52 +0000 (07:58 -0700)
This reverts commit c9941ccf24cf19e6ac73ee1f6407304949acaa85, reversing
changes made to af4fb9c4039b2d1aecc303ff2b6355b933397c57. CI failed on Windows.

22 files changed:
CHANGELOG.md
cmd/gvmap/cluster.c
cmd/gvmap/gvmap.c
cmd/tools/ccomps.c
cmd/tools/gc.c
cmd/tools/gml2gv.c
cmd/tools/gmlparse.y
cmd/tools/graphml2gv.c
cmd/tools/gv2gxl.c
cmd/tools/gxl2gv.c
cmd/tools/tred.c
lib/cgraph/agxbuf.c
lib/common/memory.c
lib/common/memory.h
lib/common/routespl.c
lib/dotgen/decomp.c
lib/label/index.c
lib/pack/ccomps.c
lib/sfdpgen/post_process.c
lib/sparse/general.h
plugin/pango/gvgetfontlist_pango.c
plugin/pango/gvtextlayout_pango.c

index c279769dc9644819b70afbc3992c78e99699a7f0..a45020694858bf30d356a5eede4bee32e6a44ce6 100644 (file)
@@ -11,7 +11,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
   - graphviz-2.42.2-coverity-scan-fixes.patch
   - graphviz-2.42.2-dotty-menu-fix.patch
   - graphviz-2.42.2-ocaml-allow-const-cast.patch
-- some allocation failures that could previously allow memory corruption now exit
 
 ### Fixed
 - Released Ubuntu packages does not contain language bindings for Python3 #1737
index 6840d4494e9cb5dc69d09407229c8cedbd146b9a..55e4d587fce320a61850fe0519e48a4f680ad689 100644 (file)
@@ -54,6 +54,32 @@ typedef struct {
   int clustering_method;
 } opts_t;
 
+#if 0
+void *gmalloc(size_t nbytes)
+{
+    char *rv;
+    if (nbytes == 0)
+        return NULL;
+    rv = malloc(nbytes);
+    if (rv == NULL) {
+        fprintf(stderr, "out of memory\n");
+        abort();
+    }
+    return rv;
+}
+
+void *grealloc(void *ptr, size_t size)
+{
+    void *p = realloc(ptr, size);
+    if (p == NULL && size) {
+        fprintf(stderr, "out of memory\n");
+        abort();
+    }
+    return p;
+}
+
+#endif
+
 static char* usestr =
 "    -C k - generate no more than k clusters (0)\n\
        0 : no limit\n\
index 7550177afcb532ae104634f2e2d6a23753a0a2ba..7a74e665673356005d706eec7bccbe6cc1f926fd 100644 (file)
@@ -40,6 +40,32 @@ enum {maxlen = 10000000};
 enum {MAX_GRPS = 10000};
 static char swork[maxlen];
 
+#if 0
+void *gmalloc(size_t nbytes)
+{
+    char *rv;
+    if (nbytes == 0)
+        return NULL;
+    rv = malloc(nbytes);
+    if (rv == NULL) {
+        fprintf(stderr, "out of memory\n");
+        abort();
+    }
+    return rv;
+}
+
+void *grealloc(void *ptr, size_t size)
+{
+    void *p = realloc(ptr, size);
+    if (p == NULL && size) {
+        fprintf(stderr, "out of memory\n");
+        abort();
+    }
+    return p;
+}
+
+#endif
+
 typedef struct {
     char* cmd;
     char **infiles; 
index 3207fb207b3326ead3d0a04a053221c62b7cf27c..8aa79c5a0b27b1af7e5b226996d177f3708f605c 100644 (file)
@@ -23,7 +23,7 @@
 #include <stdlib.h>
 #include "cgraph.h"
 
-#define N_NEW(n,t)       (t*)calloc((n),sizeof(t))
+#define N_NEW(n,t)       (t*)malloc((n)*sizeof(t))
 #define NEW(t)           (t*)malloc(sizeof(t))
 
 typedef struct {
index 5f03b2aa4150a6c87d7762347dd03a4830281b95..2645e73d792cef5a62fd64abde259024dd260268 100644 (file)
@@ -25,7 +25,7 @@
 #include <string.h>
 
 #define NEW(t)           (t*)malloc(sizeof(t))
-#define N_NEW(n,t)       (t*)calloc((n),sizeof(t))
+#define N_NEW(n,t)       (t*)malloc((n)*sizeof(t))
 
 #include "cgraph.h"
 #include "cghdr.h"
index e3462892ba108f03cd3c7f6cce382576947c1d42..edfdf8c93336760eb97f19264cb73c803f20bee9 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <getopt.h>
 
-#define N_NEW(n,t)       (t*)calloc((n),sizeof(t))
+#define N_NEW(n,t)       (t*)malloc((n)*sizeof(t))
 
 static int Verbose;
 static char* gname = "";
index 674691bf6386c3a5b8071324a60844341a91573a..959d64c810fcc6bd399cfe9804e482086f849cd3 100644 (file)
@@ -21,7 +21,7 @@
 #include <assert.h>
 
 #define NEW(t)       (t*)malloc(sizeof(t))
-#define N_NEW(n,t)   (t*)calloc((n),sizeof(t))
+#define N_NEW(n,t)   (t*)malloc((n)*sizeof(t))
 #define RALLOC(size,ptr,type) ((type*)realloc(ptr,(size)*sizeof(type)))
 
 typedef unsigned short ushort;
index ea7df59ad6cbbfb18598e24d3b36870de8ce4b3f..e3ae1dbbac890aa91982dd1e32f71755af20445d 100644 (file)
@@ -56,7 +56,7 @@ struct slist {
 };
 
 #define NEW(t)      (t*)malloc(sizeof(t))
-#define N_NEW(n,t)  (t*)calloc((n),sizeof(t))
+#define N_NEW(n,t)  (t*)malloc((n)*sizeof(t))
 /* Round x up to next multiple of y, which is a power of 2 */
 #define ROUND2(x,y) (((x) + ((y)-1)) & ~((y)-1))
 
index 78fac09f07510c5b8f5ae4c82a5d9d5d056b3f75..89a5a2b8b0d0dc06a2b8350f539df014f3034254 100644 (file)
@@ -18,7 +18,7 @@
 #define SMALLBUF    128
 
 #define NEW(t)      (t*)malloc(sizeof(t))
-#define N_NEW(n,t)  (t*)calloc((n),sizeof(t))
+#define N_NEW(n,t)  (t*)malloc((n)*sizeof(t))
 #define EMPTY(s)       ((s == 0) || (*s == '\0'))
 #define SLEN(s)     (sizeof(s)-1)
 
index 107f123faffe69dcff781a9021e8ba64fb4faca1..bb0d67cb3185b51b90b7ba7e8f43d4acdf73d583 100644 (file)
@@ -49,7 +49,7 @@ struct slist {
 };
 
 #define NEW(t)      (t*)malloc(sizeof(t))
-#define N_NEW(n,t)  (t*)calloc((n),sizeof(t))
+#define N_NEW(n,t)  (t*)malloc((n)*sizeof(t))
 /* Round x up to next multiple of y, which is a power of 2 */
 #define ROUND2(x,y) (((x) + ((y)-1)) & ~((y)-1))
 
index cae064734743368d3f86def65ef95aca59b60e89..d3917d5ba2bc0662972bb1cc83f5093fec33cfc3 100644 (file)
@@ -28,7 +28,7 @@
 #include <stdlib.h>
 
 #define NEW(t)           (t*)malloc(sizeof(t))
-#define N_NEW(n,t)       (t*)calloc((n),sizeof(t))
+#define N_NEW(n,t)       (t*)malloc((n)*sizeof(t))
 
 typedef struct {
     unsigned char on_stack;
index 4e320670aae3181038caea283a24fbcf1171fe14..a2a71df0109909cfe65579718a1ad19b0fa481eb 100644 (file)
@@ -17,7 +17,7 @@
 #include <string.h>
 #include <agxbuf.h>
 
-#define N_GNEW(n,t)     (t*)calloc((n),sizeof(t))
+#define N_GNEW(n,t)     (t*)malloc((n)*sizeof(t))
 
 /* agxbinit:
  * Assume if init is non-null, hint = sizeof(init[])
index 53bb083af429b35c2d1e2c02ff64688fd2af0798..2c6649e6bcae8c0e7d185d8359f78fb4bfc9908f 100644 (file)
 #include "config.h"
 
 #include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 #include "memory.h"
 
 void *zmalloc(size_t nbytes)
 {
+    char *rv;
     if (nbytes == 0)
        return 0;
-    return gcalloc(1, nbytes);
+    rv = gmalloc(nbytes);
+    memset(rv, 0, nbytes);
+    return rv;
 }
 
 void *zrealloc(void *ptr, size_t size, size_t elt, size_t osize)
@@ -30,23 +32,13 @@ void *zrealloc(void *ptr, size_t size, size_t elt, size_t osize)
     void *p = realloc(ptr, size * elt);
     if (p == NULL && size) {
        fprintf(stderr, "out of memory\n");
-       exit(EXIT_FAILURE);
+       return p;
     }
     if (osize < size)
        memset((char *) p + (osize * elt), '\0', (size - osize) * elt);
     return p;
 }
 
-void *gcalloc(size_t nmemb, size_t size)
-{
-    char *rv = calloc(nmemb, size);
-    if (rv == NULL) {
-       fprintf(stderr, "out of memory\n");
-       exit(EXIT_FAILURE);
-    }
-    return rv;
-}
-
 void *gmalloc(size_t nbytes)
 {
     char *rv;
@@ -55,7 +47,6 @@ void *gmalloc(size_t nbytes)
     rv = malloc(nbytes);
     if (rv == NULL) {
        fprintf(stderr, "out of memory\n");
-       exit(EXIT_FAILURE);
     }
     return rv;
 }
@@ -65,7 +56,6 @@ void *grealloc(void *ptr, size_t size)
     void *p = realloc(ptr, size);
     if (p == NULL && size) {
        fprintf(stderr, "out of memory\n");
-       exit(EXIT_FAILURE);
     }
     return p;
 }
index cccea10708e414f931e632762767cd63a4dba586..1f0c53c919d45a7a11341f743892f7d1391a3aa1 100644 (file)
@@ -24,11 +24,11 @@ extern "C" {
 #endif
 
 #define NEW(t)           (t*)zmalloc(sizeof(t))
-#define N_NEW(n,t)       (t*)gcalloc((n),sizeof(t))
+#define N_NEW(n,t)       (t*)zmalloc((n)*sizeof(t))
 #define GNEW(t)          (t*)gmalloc(sizeof(t))
 
-#define N_GNEW(n,t)      (t*)gcalloc((n),sizeof(t))
-#define N_GGNEW(n,t)      (t*)calloc((n),sizeof(t))
+#define N_GNEW(n,t)      (t*)gmalloc((n)*sizeof(t))
+#define N_GGNEW(n,t)      (t*)malloc((n)*sizeof(t))
 #define ALLOC(size,ptr,type) (ptr? (type*)grealloc(ptr,(size)*sizeof(type)):(type*)gmalloc((size)*sizeof(type)))
 #define RALLOC(size,ptr,type) ((type*)grealloc(ptr,(size)*sizeof(type)))
 #define ZALLOC(size,ptr,type,osize) (ptr? (type*)zrealloc(ptr,size,sizeof(type),osize):(type*)zmalloc((size)*sizeof(type)))
@@ -45,7 +45,6 @@ extern "C" {
 
     extern void *zmalloc(size_t);
     extern void *zrealloc(void *, size_t, size_t, size_t);
-    extern void *gcalloc(size_t nmemb, size_t size);
     extern void *gmalloc(size_t);
        extern void *grealloc(void *, size_t);
 #undef extern
index 89a3c2aaf60e2d3c2aa4e14d7922c4649fdb52e4..d993ca008decff77369a6effb367564eb18db921 100644 (file)
@@ -16,7 +16,6 @@
 #include "render.h"
 #include "pathplan.h"
 #include <setjmp.h>
-#include <stdlib.h>
 
 #ifdef UNUSED
 static box *bs = NULL;
@@ -289,7 +288,7 @@ int
 routesplinesinit()
 {
     if (++routeinit > 1) return 0;
-    if (!(ps = calloc(PINC, sizeof(pointf)))) {
+    if (!(ps = N_GNEW(PINC, pointf))) {
        agerr(AGERR, "routesplinesinit: cannot allocate ps\n");
        return 1;
     }
@@ -847,7 +846,7 @@ static int mkspacep(int size)
 {
     if (size > maxpn) {
        int newmax = maxpn + (size / PINC + 1) * PINC;
-       ps = realloc(ps, newmax * sizeof(pointf));
+       ps = RALLOC(newmax, ps, pointf);
        if (!ps) {
            agerr(AGERR, "cannot re-allocate ps\n");
            return 1;
index 7af7233a969191f0a2e3ef23653fd5311fb7e83c..01bae58c415376bcde7acb1f2c9c8e5b90687fbe 100644 (file)
@@ -99,9 +99,15 @@ static void push(stk_t* sp, node_t * np)
     if (sp->curp == sp->curblk->endp) {
         if (sp->curblk->next == NULL) {
             blk_t *bp = NEW(blk_t);
+            if (bp == 0) {
+                agerr(AGERR, "gc: Out of memory\n");
+            }
             bp->prev = sp->curblk;
             bp->next = NULL;
             bp->data = N_NEW(BIGBUF, Agnode_t *);
+            if (bp->data == 0) {
+                agerr(AGERR, "dot: Out of memory\n");
+            }
             bp->endp = bp->data + BIGBUF;
             sp->curblk->next = bp;
         }
index bd769a6990586ba2192c330b02e31a9a5b61c970..bd3dcd58523a58c97712eaa4520e7c2ed56ef3d7 100644 (file)
@@ -22,7 +22,7 @@ LeafList_t *RTreeNewLeafList(Leaf_t * lp)
 {
     LeafList_t *llp;
 
-    if ((llp = calloc(1, sizeof(LeafList_t)))) {
+    if ((llp = NEW(LeafList_t))) {
        llp->leaf = lp;
        llp->next = 0;
     }
@@ -57,7 +57,7 @@ void RTreeLeafListFree(LeafList_t * llp)
  */
 static struct ListNode *RTreeNewListNode(void)
 {
-    return calloc(1, sizeof(struct ListNode));
+    return NEW(struct ListNode);
 }
 
 #if UNUSED
@@ -86,7 +86,7 @@ RTree_t *RTreeOpen()
 {
     RTree_t *rtp;
 
-    if ((rtp = calloc(1, sizeof(RTree_t))))
+    if ((rtp = NEW(RTree_t)))
        rtp->root = RTreeNewIndex(rtp);
     return rtp;
 }
@@ -468,3 +468,14 @@ RTreeDelete2(RTree_t * rtp, Rect_t * r, void *data, Node_t * n,
        return 1;
     }
 }
+
+#ifdef UNUSED
+/* Allocate space for a node in the list used in DeletRect to
+** store Nodes that are too empty.
+*/
+struct ListNode *NewListNode()
+{
+    return (struct ListNode *) NEW(sizeof(struct ListNode));
+}
+
+#endif
index fdc0279ec4620a908443c23239431ce1f726612a..9f8d27c9676ed40818e213922c858ac6d1a27ccc 100644 (file)
@@ -14,7 +14,6 @@
 
 #include <ctype.h>
 #include <setjmp.h>
-#include <stdlib.h>
 #include "render.h"
 #include "pack.h"
 
@@ -75,14 +74,14 @@ static void push(stk_t* sp, Agnode_t * np)
 {
     if (sp->curp == sp->curblk->endp) {
        if (sp->curblk->next == NULL) {
-           blk_t *bp = malloc(sizeof(blk_t));
+           blk_t *bp = GNEW(blk_t);
            if (bp == 0) {
                agerr(AGERR, "gc: Out of memory\n");
                longjmp(jbuf, 1);
            }
            bp->prev = sp->curblk;
            bp->next = NULL;
-           bp->data = calloc(BIGBUF, sizeof(Agnode_t *));
+           bp->data = N_GNEW(BIGBUF, Agnode_t *);
            if (bp->data == 0) {
                agerr(AGERR, "gc: Out of memory\n");
                longjmp(jbuf, 1);
@@ -175,7 +174,7 @@ setPrefix (char* pfx, int* lenp, char* buf, int buflen)
     if (len + 25 <= buflen)
         name = buf;
     else {
-        name = (char *) gmalloc(len + 25);
+        if (!(name = (char *) gmalloc(len + 25))) return NULL;
     }
     strcpy(name, pfx);
     *lenp = len;
index 4e6669cc2d138f03d7e567f9c06d565213ee7b24..0e8aa8a4307d71c50a76ee207fba1bdcdb74f4ab 100644 (file)
@@ -16,7 +16,6 @@
 #include <time.h>
 #include <string.h>
 #include <math.h>
-#include <stdlib.h>
 
 #include "types.h"
 #include "memory.h"
@@ -820,11 +819,11 @@ real StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, r
 
   Lwdd = SparseMatrix_copy(Lwd);
   m = Lw->m;
-  x0 = calloc(dim*m, sizeof(real));
+  x0 = N_GNEW(dim*m,real);
   if (!x0) goto RETURN;
 
   memcpy(x0, x, sizeof(real)*dim*m);
-  y = calloc(dim*m, sizeof(real));
+  y = N_GNEW(dim*m,real);
   if (!y) goto RETURN;
 
   id = Lwd->ia; jd = Lwd->ja;
index 0dd0e7c97d01dbd0ea960a2068a38a7dfe6dac06..5d788051f02c4da29eb8919e99015bf657d467d5 100644 (file)
@@ -41,7 +41,7 @@
 #define MALLOC malloc
 #define REALLOC realloc
 
-#define N_NEW(n,t)   (t*)calloc((n),sizeof(t))
+#define N_NEW(n,t)   (t*)malloc((n)*sizeof(t))
 #define NEW(t)       (t*)malloc(sizeof(t))
 #define MAX(a,b) ((a)>(b)?(a):b)
 #define MIN(a,b) ((a)<(b)?(a):b)
index d696e692f1c70143bfa36aa9fb09c19d8069e125..3ce61364835b624c305e78fbfeba9e919ce6bfc0 100644 (file)
@@ -245,7 +245,7 @@ typedef struct {
 } availfont_t;
 
 #define NEW(t)          (t*)malloc(sizeof(t))
-#define N_NEW(n,t)      (t*)calloc((n),sizeof(t))
+#define N_NEW(n,t)      (t*)malloc((n)*sizeof(t))
 
 static PostscriptAlias postscript_alias[] = {
 #include "ps_font_equiv.h"
index 0927c438482f5f36ba04334ba42707870d528d44..9b102d97f6791e73141f2c2522db1ed49a5113fa 100644 (file)
@@ -26,6 +26,8 @@
 #include <pango/pangofc-font.h>
 #endif
 
+#define N_NEW(n,t)      (t*)malloc((n)*sizeof(t))
+
 static void pango_free_layout (void *layout)
 {
     g_object_unref((PangoLayout*)layout);