[poppler] poppler/goo: gmem.c,1.2,1.3 gmem.h,1.2,1.3

Brad Hards bradh at freedesktop.org
Sat Aug 27 01:43:45 PDT 2005


Update of /cvs/poppler/poppler/goo
In directory gabe:/tmp/cvs-serv7837/goo

Modified Files:
	gmem.c gmem.h 
Log Message:
Merge the gmalloc -> gmallocn changes from xpdf 3.0.1. This change is
based on martink's work (13-xpdf-3.01-goo-allocn.patch) with some
tweaking by me. There may be some residual gmallocn changes still to
be merged.


Index: gmem.c
===================================================================
RCS file: /cvs/poppler/poppler/goo/gmem.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- gmem.c	1 May 2005 21:54:55 -0000	1.2
+++ gmem.c	27 Aug 2005 08:43:43 -0000	1.3
@@ -135,6 +135,28 @@
 #endif
 }
 
+void *gmallocn(int nObjs, int objSize) {
+  int n;
+
+  n = nObjs * objSize;
+  if (objSize == 0 || n / objSize != nObjs) {
+    fprintf(stderr, "Bogus memory allocation size\n");
+    exit(1);
+  }
+  return gmalloc(n);
+}
+
+void *greallocn(void *p, int nObjs, int objSize) {
+  int n;
+
+  n = nObjs * objSize;
+  if (objSize == 0 || n / objSize != nObjs) {
+    fprintf(stderr, "Bogus memory allocation size\n");
+    exit(1);
+  }
+  return grealloc(p, n);
+}
+
 void gfree(void *p) {
 #ifdef DEBUG_MEM
   size_t size;

Index: gmem.h
===================================================================
RCS file: /cvs/poppler/poppler/goo/gmem.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- gmem.h	1 May 2005 21:54:55 -0000	1.2
+++ gmem.h	27 Aug 2005 08:43:43 -0000	1.3
@@ -28,6 +28,15 @@
 extern void *grealloc(void *p, size_t size);
 
 /*
+ * These are similar to gmalloc and grealloc, but take an object count
+ * and size.  The result is similar to allocating nObjs * objSize
+ * bytes, but there is an additional error check that the total size
+ * doesn't overflow an int.
+ */
+extern void *gmallocn(int nObjs, int objSize);
+extern void *greallocn(void *p, int nObjs, int objSize);
+
+/*
  * Same as free, but checks for and ignores NULL pointers.
  */
 extern void gfree(void *p);



More information about the poppler mailing list