catch malloc(0)/calloc(0) with an assert

Actually, it turns out we now should never call these functions
with a zero size, otherwise something is wrong in the logic.

Change-Id: Ie414fcbec95486c169190470a71f2cff0843782a
This commit is contained in:
skal 2013-01-23 20:08:49 +01:00
parent 152ec3d2ee
commit 757ebcb1c1

View File

@ -30,12 +30,14 @@ static int CheckSizeArgumentsOverflow(uint64_t nmemb, size_t size) {
void* WebPSafeMalloc(uint64_t nmemb, size_t size) {
if (!CheckSizeArgumentsOverflow(nmemb, size)) return NULL;
return (nmemb > 0 && size > 0) ? malloc((size_t)(nmemb * size)) : NULL;
assert(nmemb * size > 0);
return malloc((size_t)(nmemb * size));
}
void* WebPSafeCalloc(uint64_t nmemb, size_t size) {
if (!CheckSizeArgumentsOverflow(nmemb, size)) return NULL;
return (nmemb > 0 && size > 0) ? calloc((size_t)nmemb, size) : NULL;
assert(nmemb * size > 0);
return calloc((size_t)nmemb, size);
}
//------------------------------------------------------------------------------