Commit ea72a3f3 authored by Albert Astals Cid's avatar Albert Astals Cid

gmallocn: move the operation after the checks

fixes oss-fuzz/8423
parent aa39d079
......@@ -178,17 +178,15 @@ void *grealloc_checkoverflow(void *p, size_t size) {
}
inline static void *gmallocn(int nObjs, int objSize, bool checkoverflow) {
int n;
if (nObjs == 0) {
return nullptr;
}
n = nObjs * objSize;
if (objSize <= 0 || nObjs < 0 || nObjs >= INT_MAX / objSize) {
fprintf(stderr, "Bogus memory allocation size\n");
if (checkoverflow) return nullptr;
else exit(1);
}
const int n = nObjs * objSize;
return gmalloc(n, checkoverflow);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment