summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAriadne Conill <ariadne@dereferenced.org>2020-08-01 08:26:35 -0600
committerRich Felker <dalias@aerifal.cx>2020-11-30 16:49:58 -0500
commit821083ac7b54eaa040d5a8ddc67c6206a175e0ca (patch)
tree530083ea1ed16cb8cffbe23ea2c5e9b121b23bad /src
parent29ff7599a448232f2527841c2362643d246cee36 (diff)
downloadmusl-821083ac7b54eaa040d5a8ddc67c6206a175e0ca.tar.gz
musl-821083ac7b54eaa040d5a8ddc67c6206a175e0ca.tar.bz2
musl-821083ac7b54eaa040d5a8ddc67c6206a175e0ca.tar.xz
musl-821083ac7b54eaa040d5a8ddc67c6206a175e0ca.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/malloc/reallocarray.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/malloc/reallocarray.c b/src/malloc/reallocarray.c
new file mode 100644
index 00000000..4a6ebe46
--- /dev/null
+++ b/src/malloc/reallocarray.c
@@ -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);
+}