summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2009-04-11 00:20:55 +0200
committerAlbert Astals Cid <aacid@kde.org>2009-04-11 00:20:55 +0200
commit0131f0a01cba8691d10a18de1137a4744988b346 (patch)
treed0898a46f3040ad6cb510257b6645eddc355df42
parent75c3466ba2e4980802e80b939495981240261cd5 (diff)
Add gmallocn3 that does the same as gmallocn but with 3 arguments
-rw-r--r--goo/gmem.cc22
-rw-r--r--goo/gmem.h2
2 files changed, 24 insertions, 0 deletions
diff --git a/goo/gmem.cc b/goo/gmem.cc
index 298d5ddb..af3e19ef 100644
--- a/goo/gmem.cc
+++ b/goo/gmem.cc
@@ -216,6 +216,28 @@ void *gmallocn_checkoverflow(int nObjs, int objSize) GMEM_EXCEP {
return gmallocn(nObjs, objSize, true);
}
+inline static void *gmallocn3(int a, int b, int c, bool checkoverflow) GMEM_EXCEP {
+ int n = a * b;
+ if (b <= 0 || a < 0 || a >= INT_MAX / b) {
+#if USE_EXCEPTIONS
+ throw GMemException();
+#else
+ fprintf(stderr, "Bogus memory allocation size\n");
+ if (checkoverflow) return NULL;
+ else exit(1);
+#endif
+ }
+ return gmallocn(n, c, checkoverflow);
+}
+
+void *gmallocn3(int a, int b, int c) GMEM_EXCEP {
+ return gmallocn3(a, b, c, false);
+}
+
+void *gmallocn3_checkoverflow(int a, int b, int c) GMEM_EXCEP {
+ return gmallocn3(a, b, c, true);
+}
+
inline static void *greallocn(void *p, int nObjs, int objSize, bool checkoverflow) GMEM_EXCEP {
int n;
diff --git a/goo/gmem.h b/goo/gmem.h
index 96d834de..0c16b01c 100644
--- a/goo/gmem.h
+++ b/goo/gmem.h
@@ -72,6 +72,8 @@ extern void *grealloc_checkoverflow(size_t size) GMEM_EXCEP;
*/
extern void *gmallocn(int nObjs, int objSize) GMEM_EXCEP;
extern void *gmallocn_checkoverflow(int nObjs, int objSize) GMEM_EXCEP;
+extern void *gmallocn3(int a, int b, int c) GMEM_EXCEP;
+extern void *gmallocn3_checkoverflow(int a, int b, int c) GMEM_EXCEP;
extern void *greallocn(void *p, int nObjs, int objSize) GMEM_EXCEP;
extern void *greallocn_checkoverflow(void *p, int nObjs, int objSize) GMEM_EXCEP;