summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-12-10 13:49:56 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-12-11 15:36:06 -0800
commite02e32f71f6c24fcc69bdaf58f6f9e973a017896 (patch)
tree942bf0f4eafd2fac63249fb0250c4867403abde5
parent75af06f5f8ffc41fabd100253aad222cb4ab8662 (diff)
downloadxorg-app-xkbcomp-e02e32f71f6c24fcc69bdaf58f6f9e973a017896.tar.gz
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.ac7
-rw-r--r--listing.c4
-rw-r--r--utils.c11
-rw-r--r--utils.h8
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
@@ -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;
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)))
/***====================================================================***/