diff options
author | Cameron Katri <me@cameronkatri.com> | 2021-04-08 15:26:55 -0400 |
---|---|---|
committer | Cameron Katri <me@cameronkatri.com> | 2021-04-08 15:26:55 -0400 |
commit | 97cf6d8bc6280611a347acf60e678721957475d0 (patch) | |
tree | e52fa41b1bcfb460b9ab6ffdbc08cb124856ea9d | |
parent | d0c36b7ba551609dd9355c6791f1ae9b55f1bc33 (diff) | |
download | pw-darwin-97cf6d8bc6280611a347acf60e678721957475d0.tar.gz pw-darwin-97cf6d8bc6280611a347acf60e678721957475d0.tar.zst pw-darwin-97cf6d8bc6280611a347acf60e678721957475d0.zip |
Use libc reallocarray
-rw-r--r-- | pw/Makefile | 1 | ||||
-rw-r--r-- | pw/libutil/gr_util.c | 4 | ||||
-rw-r--r-- | pw/libutil/login_cap.c | 4 | ||||
-rw-r--r-- | pw/libutil/pw_util.c | 5 | ||||
-rw-r--r-- | pw/reallocarray.c | 42 | ||||
-rw-r--r-- | pw/reallocarray.h | 1 |
6 files changed, 10 insertions, 47 deletions
diff --git a/pw/Makefile b/pw/Makefile index 59ee1bb..776d231 100644 --- a/pw/Makefile +++ b/pw/Makefile @@ -13,7 +13,6 @@ SRC := pw_utils.c \ bitmap.c \ psdate.c \ pw_nis.c \ - reallocarray.c \ pw.c \ grupd.c \ pwupd.c \ diff --git a/pw/libutil/gr_util.c b/pw/libutil/gr_util.c index cfb9b7e..bcd171e 100644 --- a/pw/libutil/gr_util.c +++ b/pw/libutil/gr_util.c @@ -47,7 +47,9 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include <pwd.h> -#include "reallocarray.h" +#include <os/availability.h> +API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) +void * reallocarray(void * in_ptr, size_t nmemb, size_t size) __DARWIN_EXTSN(reallocarray) __result_use_check; static int lockfd = -1; static char group_dir[PATH_MAX]; diff --git a/pw/libutil/login_cap.c b/pw/libutil/login_cap.c index b544b69..8befd7c 100644 --- a/pw/libutil/login_cap.c +++ b/pw/libutil/login_cap.c @@ -44,7 +44,9 @@ __FBSDID("$FreeBSD$"); #include <syslog.h> #include <unistd.h> -#include "reallocarray.h" +#include <os/availability.h> +API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) +void * reallocarray(void * in_ptr, size_t nmemb, size_t size) __DARWIN_EXTSN(reallocarray) __result_use_check; /* * allocstr() diff --git a/pw/libutil/pw_util.c b/pw/libutil/pw_util.c index 61d4ef4..1548ca6 100644 --- a/pw/libutil/pw_util.c +++ b/pw/libutil/pw_util.c @@ -65,7 +65,10 @@ __SCCSID("@(#)pw_util.c 8.3 (Berkeley) 4/2/94"); #include <unistd.h> #include "libutil.h" -#include "reallocarray.h" + +#include <os/availability.h> +API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) +void * reallocarray(void * in_ptr, size_t nmemb, size_t size) __DARWIN_EXTSN(reallocarray) __result_use_check; static pid_t editpid = -1; static int lockfd = -1; diff --git a/pw/reallocarray.c b/pw/reallocarray.c deleted file mode 100644 index e1e9b7c..0000000 --- a/pw/reallocarray.c +++ /dev/null @@ -1,42 +0,0 @@ -/* $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/cdefs.h> -__FBSDID("$FreeBSD$"); - -#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)); -} diff --git a/pw/reallocarray.h b/pw/reallocarray.h deleted file mode 100644 index 5b01046..0000000 --- a/pw/reallocarray.h +++ /dev/null @@ -1 +0,0 @@ -void *reallocarray(void *optr, size_t nmemb, size_t size); |