cxx: add nullptr check in calloc

Even though malloc via the cxx_heap never fails, the implementation of
calloc should better not rely on this assumption.
This commit is contained in:
Norman Feske 2020-01-02 20:20:36 +01:00
parent 9321067b68
commit ffc099eb54
1 changed files with 5 additions and 1 deletions

View File

@ -87,7 +87,11 @@ extern "C" void *malloc(size_t size)
extern "C" void *calloc(size_t nmemb, size_t size)
{
void *addr = malloc(nmemb*size);
void * const addr = malloc(nmemb*size);
if (addr == nullptr)
return nullptr;
Genode::memset(addr, 0, nmemb*size);
return addr;
}