]> granicus.if.org Git - graphviz/commitdiff
swap malloc(n*m) pattern for calloc(n,m)
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 16 Jun 2020 01:04:42 +0000 (18:04 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 16 Jun 2020 14:23:28 +0000 (07:23 -0700)
This avoids some potential integer overflows.

13 files changed:
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.h
lib/graph/agxbuf.c
lib/sparse/general.h
plugin/pango/gvgetfontlist_pango.c

index 8aa79c5a0b27b1af7e5b226996d177f3708f605c..3207fb207b3326ead3d0a04a053221c62b7cf27c 100644 (file)
@@ -23,7 +23,7 @@
 #include <stdlib.h>
 #include "cgraph.h"
 
-#define N_NEW(n,t)       (t*)malloc((n)*sizeof(t))
+#define N_NEW(n,t)       (t*)calloc((n),sizeof(t))
 #define NEW(t)           (t*)malloc(sizeof(t))
 
 typedef struct {
index 2645e73d792cef5a62fd64abde259024dd260268..5f03b2aa4150a6c87d7762347dd03a4830281b95 100644 (file)
@@ -25,7 +25,7 @@
 #include <string.h>
 
 #define NEW(t)           (t*)malloc(sizeof(t))
-#define N_NEW(n,t)       (t*)malloc((n)*sizeof(t))
+#define N_NEW(n,t)       (t*)calloc((n),sizeof(t))
 
 #include "cgraph.h"
 #include "cghdr.h"
index edfdf8c93336760eb97f19264cb73c803f20bee9..e3462892ba108f03cd3c7f6cce382576947c1d42 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <getopt.h>
 
-#define N_NEW(n,t)       (t*)malloc((n)*sizeof(t))
+#define N_NEW(n,t)       (t*)calloc((n),sizeof(t))
 
 static int Verbose;
 static char* gname = "";
index 959d64c810fcc6bd399cfe9804e482086f849cd3..674691bf6386c3a5b8071324a60844341a91573a 100644 (file)
@@ -21,7 +21,7 @@
 #include <assert.h>
 
 #define NEW(t)       (t*)malloc(sizeof(t))
-#define N_NEW(n,t)   (t*)malloc((n)*sizeof(t))
+#define N_NEW(n,t)   (t*)calloc((n),sizeof(t))
 #define RALLOC(size,ptr,type) ((type*)realloc(ptr,(size)*sizeof(type)))
 
 typedef unsigned short ushort;
index e3ae1dbbac890aa91982dd1e32f71755af20445d..ea7df59ad6cbbfb18598e24d3b36870de8ce4b3f 100644 (file)
@@ -56,7 +56,7 @@ struct slist {
 };
 
 #define NEW(t)      (t*)malloc(sizeof(t))
-#define N_NEW(n,t)  (t*)malloc((n)*sizeof(t))
+#define N_NEW(n,t)  (t*)calloc((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 89a5a2b8b0d0dc06a2b8350f539df014f3034254..78fac09f07510c5b8f5ae4c82a5d9d5d056b3f75 100644 (file)
@@ -18,7 +18,7 @@
 #define SMALLBUF    128
 
 #define NEW(t)      (t*)malloc(sizeof(t))
-#define N_NEW(n,t)  (t*)malloc((n)*sizeof(t))
+#define N_NEW(n,t)  (t*)calloc((n),sizeof(t))
 #define EMPTY(s)       ((s == 0) || (*s == '\0'))
 #define SLEN(s)     (sizeof(s)-1)
 
index bb0d67cb3185b51b90b7ba7e8f43d4acdf73d583..107f123faffe69dcff781a9021e8ba64fb4faca1 100644 (file)
@@ -49,7 +49,7 @@ struct slist {
 };
 
 #define NEW(t)      (t*)malloc(sizeof(t))
-#define N_NEW(n,t)  (t*)malloc((n)*sizeof(t))
+#define N_NEW(n,t)  (t*)calloc((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 d3917d5ba2bc0662972bb1cc83f5093fec33cfc3..cae064734743368d3f86def65ef95aca59b60e89 100644 (file)
@@ -28,7 +28,7 @@
 #include <stdlib.h>
 
 #define NEW(t)           (t*)malloc(sizeof(t))
-#define N_NEW(n,t)       (t*)malloc((n)*sizeof(t))
+#define N_NEW(n,t)       (t*)calloc((n),sizeof(t))
 
 typedef struct {
     unsigned char on_stack;
index a2a71df0109909cfe65579718a1ad19b0fa481eb..4e320670aae3181038caea283a24fbcf1171fe14 100644 (file)
@@ -17,7 +17,7 @@
 #include <string.h>
 #include <agxbuf.h>
 
-#define N_GNEW(n,t)     (t*)malloc((n)*sizeof(t))
+#define N_GNEW(n,t)     (t*)calloc((n),sizeof(t))
 
 /* agxbinit:
  * Assume if init is non-null, hint = sizeof(init[])
index 6d08dd8cf0aae70b9523bec74735688bdf4a413f..cccea10708e414f931e632762767cd63a4dba586 100644 (file)
@@ -24,11 +24,11 @@ extern "C" {
 #endif
 
 #define NEW(t)           (t*)zmalloc(sizeof(t))
-#define N_NEW(n,t)       (t*)zmalloc((n)*sizeof(t))
+#define N_NEW(n,t)       (t*)gcalloc((n),sizeof(t))
 #define GNEW(t)          (t*)gmalloc(sizeof(t))
 
-#define N_GNEW(n,t)      (t*)gmalloc((n)*sizeof(t))
-#define N_GGNEW(n,t)      (t*)malloc((n)*sizeof(t))
+#define N_GNEW(n,t)      (t*)gcalloc((n),sizeof(t))
+#define N_GGNEW(n,t)      (t*)calloc((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)))
index 3abd8ad35de58a92329969f9e3dd0bb399190d24..14360aa94ebc78fa12a85e15d04770795d7ca71d 100644 (file)
@@ -17,7 +17,7 @@
 #include <string.h>
 #include <agxbuf.h>
 
-#define N_GNEW(n,t)     (t*)malloc((n)*sizeof(t))
+#define N_GNEW(n,t)     (t*)calloc((n),sizeof(t))
 
 /* agxbinit:
  * Assume if init is non-null, hint = sizeof(init[])
index 5d788051f02c4da29eb8919e99015bf657d467d5..0dd0e7c97d01dbd0ea960a2068a38a7dfe6dac06 100644 (file)
@@ -41,7 +41,7 @@
 #define MALLOC malloc
 #define REALLOC realloc
 
-#define N_NEW(n,t)   (t*)malloc((n)*sizeof(t))
+#define N_NEW(n,t)   (t*)calloc((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 3ce61364835b624c305e78fbfeba9e919ce6bfc0..d696e692f1c70143bfa36aa9fb09c19d8069e125 100644 (file)
@@ -245,7 +245,7 @@ typedef struct {
 } availfont_t;
 
 #define NEW(t)          (t*)malloc(sizeof(t))
-#define N_NEW(n,t)      (t*)malloc((n)*sizeof(t))
+#define N_NEW(n,t)      (t*)calloc((n),sizeof(t))
 
 static PostscriptAlias postscript_alias[] = {
 #include "ps_font_equiv.h"