diff options
author | Albert Astals Cid <aacid@kde.org> | 2009-04-11 00:20:55 +0200 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2009-04-11 00:20:55 +0200 |
commit | 0131f0a01cba8691d10a18de1137a4744988b346 (patch) | |
tree | d0898a46f3040ad6cb510257b6645eddc355df42 | |
parent | 75c3466ba2e4980802e80b939495981240261cd5 (diff) |
Add gmallocn3 that does the same as gmallocn but with 3 arguments
-rw-r--r-- | goo/gmem.cc | 22 | ||||
-rw-r--r-- | goo/gmem.h | 2 |
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; @@ -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; |