mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/oneway-malloc: check calloc args
This commit is contained in:
parent
0695389dc2
commit
e44fa2ba3e
@ -61,6 +61,11 @@ void __attribute__((weak)) *realloc(void *ptr, size_t size)
|
||||
|
||||
void __attribute__((weak)) *calloc(size_t size, size_t cnt)
|
||||
{
|
||||
/* ensure size * cnt doesn't overflow size_t */
|
||||
if (cnt && size > (size_t)-1 / cnt) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *mem = malloc(size * cnt);
|
||||
if (mem) {
|
||||
memset(mem, 0, size * cnt);
|
||||
|
Loading…
Reference in New Issue
Block a user