diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-12-10 13:49:56 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-12-11 15:36:06 -0800 |
commit | e02e32f71f6c24fcc69bdaf58f6f9e973a017896 (patch) | |
tree | 942bf0f4eafd2fac63249fb0250c4867403abde5 | |
parent | 75af06f5f8ffc41fabd100253aad222cb4ab8662 (diff) |
Replace uTypedRealloc() with direct reallocarray() calls
Falls back to realloc() if platform doesn't offer reallocarray().
Also removes uRealloc() since it had no other uses.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | configure.ac | 7 | ||||
-rw-r--r-- | listing.c | 4 | ||||
-rw-r--r-- | utils.c | 11 | ||||
-rw-r--r-- | utils.h | 8 |
4 files changed, 12 insertions, 18 deletions
diff --git a/configure.ac b/configure.ac index 3aedf48..bdf5589 100644 --- a/configure.ac +++ b/configure.ac @@ -27,6 +27,11 @@ AC_INIT([xkbcomp], [1.4.6], AC_CONFIG_SRCDIR([Makefile.am]) AC_CONFIG_HEADERS([config.h]) +# Set common system defines for POSIX extensions, such as _GNU_SOURCE +# Must be called before any macros that run the compiler (like AC_PROG_LIBTOOL) +# to avoid autoconf errors. +AC_USE_SYSTEM_EXTENSIONS + # Initialize Automake AM_INIT_AUTOMAKE([foreign dist-xz]) @@ -45,7 +50,7 @@ if test ! -f "$srcdir/xkbparse.c"; then fi fi -AC_CHECK_FUNCS([strdup strcasecmp]) +AC_CHECK_FUNCS([reallocarray strdup strcasecmp]) # Checks for pkg-config packages PKG_CHECK_MODULES(XKBCOMP, [x11 xkbfile xproto >= 7.0.17]) @@ -155,7 +155,7 @@ AddMapOnly(char *map) szMapOnly = 5; else szMapOnly *= 2; - mapOnly = uTypedRealloc(list, szMapOnly, char *); + mapOnly = reallocarray(list, szMapOnly, sizeof(char *)); if (!mapOnly) { WSGO("Couldn't allocate list of maps\n"); @@ -175,7 +175,7 @@ AddListing(char *file, char *map) szListing = 10; else szListing *= 2; - list = uTypedRealloc(list, szListing, Listing); + list = reallocarray(list, szListing, sizeof(Listing)); if (!list) { WSGO("Couldn't allocate list of files and maps\n"); @@ -34,17 +34,6 @@ /***====================================================================***/ Opaque -uRealloc(Opaque old, unsigned newSize) -{ - if (old == NULL) - return ((Opaque) malloc(newSize)); - else - return ((Opaque) realloc((char *) old, newSize)); -} - -/***====================================================================***/ - -Opaque uRecalloc(Opaque old, unsigned nOld, unsigned nNew, unsigned itemSize) { char *rtrn; @@ -76,9 +76,10 @@ typedef int Comparison; /***====================================================================***/ -extern Opaque uRealloc(Opaque /* old */ , - unsigned /* newSize */ - ); +#ifndef HAVE_REALLOCARRAY +#define reallocarray(p, n, s) realloc(p, (n) * (s)) +#endif + extern Opaque uRecalloc(Opaque /* old */ , unsigned /* nOld */ , unsigned /* nNew */ , @@ -87,7 +88,6 @@ extern Opaque uRecalloc(Opaque /* old */ , extern void uFree(Opaque /* ptr */ ); -#define uTypedRealloc(pO,n,t) ((t *)uRealloc((Opaque)pO,((unsigned)n)*sizeof(t))) #define uTypedRecalloc(pO,o,n,t) ((t *)uRecalloc((Opaque)pO,((unsigned)o),((unsigned)n),sizeof(t))) /***====================================================================***/ |