From e02e32f71f6c24fcc69bdaf58f6f9e973a017896 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Dec 2022 13:49:56 -0800 Subject: 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 --- configure.ac | 7 ++++++- listing.c | 4 ++-- utils.c | 11 ----------- 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]) diff --git a/listing.c b/listing.c index b747482..795389b 100644 --- a/listing.c +++ b/listing.c @@ -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"); diff --git a/utils.c b/utils.c index 603e8b7..61f04b6 100644 --- a/utils.c +++ b/utils.c @@ -31,17 +31,6 @@ #include -/***====================================================================***/ - -Opaque -uRealloc(Opaque old, unsigned newSize) -{ - if (old == NULL) - return ((Opaque) malloc(newSize)); - else - return ((Opaque) realloc((char *) old, newSize)); -} - /***====================================================================***/ Opaque diff --git a/utils.h b/utils.h index 68ec887..36f9e2a 100644 --- a/utils.h +++ b/utils.h @@ -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))) /***====================================================================***/ -- cgit v1.2.3