mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 06:08:21 +01:00
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:
parent
152ec3d2ee
commit
757ebcb1c1
@ -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);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user