[hackers] [libgrapheme][PATCH] Add reallocarray implementation

From: robert <robertrussell.72001_AT_gmail.com>
Date: Sat, 30 Jul 2022 14:29:05 -0700

reallocarray is nonstandard and glibc declares it only when _GNU_SOURCE
is defined. Without this patch or _GNU_SOURCE defined, I get a seg
fault from reallocarray being implicitly declared with the wrong
signature.
---
 gen/util.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff --git a/gen/util.c b/gen/util.c
index d234ddd..c97a1ea 100644
--- a/gen/util.c
+++ b/gen/util.c
_AT_@ -31,6 +31,16 @@ struct break_test_payload
 	size_t *testlen;
 };
 
+static void *
+reallocarray(void *p, size_t len, size_t size)
+{
+	if (len > 0 && size > SIZE_MAX/len) {
+		errno = ENOMEM;
+		return NULL;
+	}
+	return realloc(p, len*size);
+}
+
 int
 hextocp(const char *str, size_t len, uint_least32_t *cp)
 {
-- 
2.17.1
Received on Sat Jul 30 2022 - 23:29:05 CEST

This archive was generated by hypermail 2.3.0 : Sun Jul 31 2022 - 03:24:36 CEST