From 97cf6d8bc6280611a347acf60e678721957475d0 Mon Sep 17 00:00:00 2001 From: Cameron Katri Date: Thu, 8 Apr 2021 15:26:55 -0400 Subject: Use libc reallocarray --- pw/Makefile | 1 - pw/libutil/gr_util.c | 4 +++- pw/libutil/login_cap.c | 4 +++- pw/libutil/pw_util.c | 5 ++++- pw/reallocarray.c | 42 ------------------------------------------ pw/reallocarray.h | 1 - 6 files changed, 10 insertions(+), 47 deletions(-) delete mode 100644 pw/reallocarray.c delete mode 100644 pw/reallocarray.h 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 #include -#include "reallocarray.h" +#include +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 #include -#include "reallocarray.h" +#include +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 #include "libutil.h" -#include "reallocarray.h" + +#include +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 - * - * 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 -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -/* - * 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); -- cgit v1.2.3-56-ge451