mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:17:44 +00:00
LibC: Make calloc() actually fail on multiplication overflow
This commit is contained in:
parent
e4c1514033
commit
1610669519
1 changed files with 4 additions and 0 deletions
|
@ -411,6 +411,10 @@ static void free_impl(void* ptr)
|
||||||
|
|
||||||
void* calloc(size_t count, size_t size)
|
void* calloc(size_t count, size_t size)
|
||||||
{
|
{
|
||||||
|
if (Checked<size_t>::multiplication_would_overflow(count, size)) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
size_t new_size = count * size;
|
size_t new_size = count * size;
|
||||||
auto* ptr = malloc_impl(new_size, CallerWillInitializeMemory::Yes);
|
auto* ptr = malloc_impl(new_size, CallerWillInitializeMemory::Yes);
|
||||||
if (ptr)
|
if (ptr)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue