fxlibc/src/stdlib/calloc.c

15 lines
266 B
C
Raw Normal View History

2021-05-09 17:34:00 +02:00
#include <stdlib.h>
#include <string.h>
2020-09-17 19:27:01 +02:00
void *calloc(size_t nmemb, size_t size)
{
unsigned int total_size;
2020-09-17 19:27:01 +02:00
if(__builtin_umul_overflow(nmemb, size, &total_size))
return NULL;
2020-09-17 19:27:01 +02:00
void *mem = malloc(total_size);
2021-09-25 15:16:24 +02:00
if(mem) memset(mem, 0, total_size);
return mem;
2020-09-17 19:27:01 +02:00
}