diff options
Diffstat (limited to 'src/utils/utils.c')
-rw-r--r-- | src/utils/utils.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/utils/utils.c b/src/utils/utils.c index b1db2f9d..673b7e28 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -19,8 +19,7 @@ extern "C" { //------------------------------------------------------------------------------ // Checked memory allocation -// Returns 0 in case of overflow of nmemb * size. -static int CheckSizeArgumentsOverflow(uint64_t nmemb, size_t size) { +static int CheckSizeArguments(uint64_t nmemb, size_t size) { const uint64_t total_size = nmemb * size; if (nmemb == 0) return 1; if ((uint64_t)size > WEBP_MAX_ALLOCABLE_MEMORY / nmemb) return 0; @@ -29,14 +28,12 @@ static int CheckSizeArgumentsOverflow(uint64_t nmemb, size_t size) { } void* WebPSafeMalloc(uint64_t nmemb, size_t size) { - if (!CheckSizeArgumentsOverflow(nmemb, size)) return NULL; - assert(nmemb * size > 0); + if (!CheckSizeArguments(nmemb, size)) return NULL; return malloc((size_t)(nmemb * size)); } void* WebPSafeCalloc(uint64_t nmemb, size_t size) { - if (!CheckSizeArgumentsOverflow(nmemb, size)) return NULL; - assert(nmemb * size > 0); + if (!CheckSizeArguments(nmemb, size)) return NULL; return calloc((size_t)nmemb, size); } |