summaryrefslogtreecommitdiffstats
path: root/libc-bottom-half/sources/reallocarray.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libc-bottom-half/sources/reallocarray.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libc-bottom-half/sources/reallocarray.c b/libc-bottom-half/sources/reallocarray.c
new file mode 100644
index 0000000..3e828cc
--- /dev/null
+++ b/libc-bottom-half/sources/reallocarray.c
@@ -0,0 +1,14 @@
+#include <stdlib.h>
+#include <errno.h>
+
+void *__reallocarray(void *ptr, size_t nmemb, size_t size) {
+ size_t bytes;
+ if (__builtin_umull_overflow(nmemb, size, &bytes)) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ return realloc(ptr, bytes);
+}
+
+void *reallocarray(void *ptr, size_t nmemb, size_t size)
+ __attribute__((__weak__, __alias__("__reallocarray")));