summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mandoc/compat_reallocarray.c
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2015-11-04 12:57:43 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2015-11-04 12:57:43 +0000
commitc2613575ef96bded8fd59bfeb14e03208bcab7b9 (patch)
tree0329d5ac287e5dcb35f78ac8f7870c50adc2f5fd /usr/src/cmd/mandoc/compat_reallocarray.c
parentfcd0d2b370a514b41cab49a8c1a30e0a1789323e (diff)
parent6357b94b54238e954e002562d0e89a2fefd982e1 (diff)
downloadillumos-joyent-c2613575ef96bded8fd59bfeb14e03208bcab7b9.tar.gz
[illumos-gate merge]
commit 6357b94b54238e954e002562d0e89a2fefd982e1 6415 sockets created via t_open/t_bind not shown by pfiles 6432 TLI sockets aren't detected correctly by pfiles in a NGZ commit 260e9a87725c090ba5835b1f9f0b62fa2f96036f 6356 Update mdocml to 1.13.3 commit 1058dba45ec5d6876a5bbb0b9174347e13e5748d 6346 zfs(1M) has spurious comma commit 3a005aada8ac0e291c13cbc488ba9ae1473f0a96 6377 Fix man page issues found by mandoc 1.13.3 commit fd76205d7372b305e64b7cfcd27939a39c743cb4 6397 libiscsit: several leaks due to left "errlist" commit a9685eaab1313767d1d4dac672c3a468519aa899 6321 mountd: The IP to name translation is usually not needed in nfsauth_access() Conflicts: usr/src/cmd/ptools/pfiles/pfiles.c
Diffstat (limited to 'usr/src/cmd/mandoc/compat_reallocarray.c')
-rw-r--r--usr/src/cmd/mandoc/compat_reallocarray.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/usr/src/cmd/mandoc/compat_reallocarray.c b/usr/src/cmd/mandoc/compat_reallocarray.c
new file mode 100644
index 0000000000..6615190425
--- /dev/null
+++ b/usr/src/cmd/mandoc/compat_reallocarray.c
@@ -0,0 +1,49 @@
+#include "config.h"
+
+#if HAVE_REALLOCARRAY
+
+int dummy;
+
+#else
+
+/* $Id: compat_reallocarray.c,v 1.4 2014/12/11 09:05:01 schwarze Exp $ */
+/* $OpenBSD: reallocarray.c,v 1.2 2014/12/08 03:45:00 bcook 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 <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);
+}
+
+#endif /*!HAVE_REALLOCARRAY*/