commit - d163c2104eb8f8603c4dfc4c9ad566511eac143b
commit + abe0273c040fe052cdead5144db761fbd52ce7b7
blob - /dev/null
blob + a12eb220f52fd230cbbec83e2892133a6dcbeaeb (mode 644)
--- /dev/null
+++ compat/reallocarray.c
+/* $OpenBSD: reallocarray.c,v 1.3 2015/09/13 08:31:47 guenther Exp $ */
+/*
+ * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "compat.h"
+
+#include <sys/types.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+/*
+ * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
+ * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
+ */
+#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
+
+void *
+reallocarray(void *optr, size_t nmemb, size_t size)
+{
+ if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
+ nmemb > 0 && SIZE_MAX / nmemb < size) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ return realloc(optr, size * nmemb);
+}
blob - 2d2216f7e204c10465ec1431d32f3643fe82713d
blob + de06e6b654820fabe2d2634479ec69a0d184441c
--- compat.h
+++ compat.h
void *memmem(const void*, size_t, const void*, size_t);
#endif
+#ifndef HAVE_REALLOCARRAY
+void *reallocarray(void*, size_t, size_t);
+#endif
+
#ifndef HAVE_RECALLOCARRAY
void *recallocarray(void*, size_t, size_t, size_t);
#endif
blob - a8ee2a6f78f72f3a016b5eec18422499923c42bb
blob + 98503dd91a0416d6137f853e09b368fd9f171227
--- configure.ac
+++ configure.ac
getdtablesize \
getprogname \
memmem \
+ reallocarray \
recallocarray \
strcasestr \
strlcat \