mirror of
git://git.musl-libc.org/musl
synced 2025-01-31 11:01:34 +00:00
implement reallocarray
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.
This commit is contained in:
parent
29ff7599a4
commit
821083ac7b
@ -145,6 +145,7 @@ int getloadavg(double *, int);
|
||||
int clearenv(void);
|
||||
#define WCOREDUMP(s) ((s) & 0x80)
|
||||
#define WIFCONTINUED(s) ((s) == 0xffff)
|
||||
void *reallocarray (void *, size_t, size_t);
|
||||
#endif
|
||||
|
||||
#ifdef _GNU_SOURCE
|
||||
|
13
src/malloc/reallocarray.c
Normal file
13
src/malloc/reallocarray.c
Normal file
@ -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
Block a user