mirror of https://git.musl-libc.org/git/musl
Browse Source
reallocarray is an extension introduced by OpenBSD, which introduces calloc overflow checking to realloc. glibc 2.28 introduced support for this function behind _GNU_SOURCE, while glibc 2.29 allows its usage in _DEFAULT_SOURCE.master
committed by
Rich Felker
2 changed files with 14 additions and 0 deletions
@ -0,0 +1,13 @@ |
|||
#define _BSD_SOURCE |
|||
#include <errno.h> |
|||
#include <stdlib.h> |
|||
|
|||
void *reallocarray(void *ptr, size_t m, size_t n) |
|||
{ |
|||
if (n && m > -1 / n) { |
|||
errno = ENOMEM; |
|||
return 0; |
|||
} |
|||
|
|||
return realloc(ptr, m * n); |
|||
} |
|||
Loading…
Reference in new issue