diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-12-10 14:07:18 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-12-11 15:36:06 -0800 |
commit | 8d85bd1e2f9473958b235caf7af9913b518f73dd (patch) | |
tree | 3348aa708638b6dbe31e9b1ca17d49465df85e8d | |
parent | e02e32f71f6c24fcc69bdaf58f6f9e973a017896 (diff) |
Replace uTypedRecalloc() with direct recallocarray() calls
Retains uRecalloc() as a fallback for platforms without recallocarray()
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | keytypes.c | 10 | ||||
-rw-r--r-- | parseutils.c | 8 | ||||
-rw-r--r-- | symbols.c | 16 | ||||
-rw-r--r-- | utils.c | 12 | ||||
-rw-r--r-- | utils.h | 15 |
6 files changed, 34 insertions, 29 deletions
diff --git a/configure.ac b/configure.ac index bdf5589..b4c2d2c 100644 --- a/configure.ac +++ b/configure.ac @@ -50,7 +50,7 @@ if test ! -f "$srcdir/xkbparse.c"; then fi fi -AC_CHECK_FUNCS([reallocarray strdup strcasecmp]) +AC_CHECK_FUNCS([reallocarray recallocarray strdup strcasecmp]) # Checks for pkg-config packages PKG_CHECK_MODULES(XKBCOMP, [x11 xkbfile xproto >= 7.0.17]) @@ -525,9 +525,9 @@ NextMapEntry(KeyTypeInfo * type) else if (type->nEntries >= type->szEntries) { type->szEntries *= 2; - type->entries = uTypedRecalloc(type->entries, - type->nEntries, type->szEntries, - XkbKTMapEntryRec); + type->entries = recallocarray(type->entries, + type->nEntries, type->szEntries, + sizeof(XkbKTMapEntryRec)); if (type->entries == NULL) { ERROR("Couldn't reallocate map entries for %s\n", TypeTxt(type)); @@ -787,8 +787,8 @@ AddLevelName(KeyTypeInfo * type, { if ((type->lvlNames == NULL) || (type->szNames <= level)) { - type->lvlNames = - uTypedRecalloc(type->lvlNames, type->szNames, level + 1, Atom); + type->lvlNames = recallocarray(type->lvlNames, type->szNames, + level + 1, sizeof(Atom)); if (type->lvlNames == NULL) { ERROR("Couldn't allocate level names for type %s\n", diff --git a/parseutils.c b/parseutils.c index 7498b75..76876fb 100644 --- a/parseutils.c +++ b/parseutils.c @@ -650,10 +650,10 @@ AppendKeysymList(ExprDef * list, char *sym) if (list->value.list.nSyms >= list->value.list.szSyms) { list->value.list.szSyms *= 2; - list->value.list.syms = uTypedRecalloc(list->value.list.syms, - list->value.list.nSyms, - list->value.list.szSyms, - char *); + list->value.list.syms = recallocarray(list->value.list.syms, + list->value.list.nSyms, + list->value.list.szSyms, + sizeof(char *)); if (list->value.list.syms == NULL) { FATAL("Couldn't resize list of symbols for append\n"); @@ -297,18 +297,18 @@ ResizeKeyGroup(KeyInfo * key, if ((key->syms[group] == NULL) || tooSmall) { - key->syms[group] = uTypedRecalloc(key->syms[group], - key->numLevels[group], newWidth, - KeySym); + key->syms[group] = recallocarray(key->syms[group], + key->numLevels[group], newWidth, + sizeof(KeySym)); if (!key->syms[group]) return False; } if (((forceActions) && (tooSmall || (key->acts[group] == NULL))) || (tooSmall && (key->acts[group] != NULL))) { - key->acts[group] = uTypedRecalloc(key->acts[group], - key->numLevels[group], newWidth, - XkbAction); + key->acts[group] = recallocarray(key->acts[group], + key->numLevels[group], newWidth, + sizeof(XkbAction)); if (!key->acts[group]) return False; } @@ -607,8 +607,8 @@ AddKeySymbols(SymbolsInfo * info, KeyInfo * key, XkbDescPtr xkb) if (info->nKeys >= info->szKeys) { info->szKeys += SYMBOLS_CHUNK; - info->keys = - uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo); + info->keys = recallocarray(info->keys, info->nKeys, info->szKeys, + sizeof(KeyInfo)); if (!info->keys) { WSGO("Could not allocate key symbols descriptions\n"); @@ -33,23 +33,25 @@ /***====================================================================***/ -Opaque -uRecalloc(Opaque old, unsigned nOld, unsigned nNew, unsigned itemSize) +#ifndef HAVE_RECALLOCARRAY +void * +uRecalloc(void *old, size_t nOld, size_t nNew, size_t itemSize) { char *rtrn; if (old == NULL) - rtrn = (char *) calloc(nNew, itemSize); + rtrn = calloc(nNew, itemSize); else { - rtrn = (char *) realloc((char *) old, nNew * itemSize); + rtrn = reallocarray(old, nNew, itemSize); if ((rtrn) && (nNew > nOld)) { bzero(&rtrn[nOld * itemSize], (nNew - nOld) * itemSize); } } - return (Opaque) rtrn; + return (void *) rtrn; } +#endif /***====================================================================***/ @@ -80,16 +80,19 @@ typedef int Comparison; #define reallocarray(p, n, s) realloc(p, (n) * (s)) #endif -extern Opaque uRecalloc(Opaque /* old */ , - unsigned /* nOld */ , - unsigned /* nNew */ , - unsigned /* newSize */ +#ifndef HAVE_RECALLOCARRAY +#define recallocarray uRecalloc + +extern void *uRecalloc(void * /* old */ , + size_t /* nOld */ , + size_t /* nNew */ , + size_t /* newSize */ ); +#endif + extern void uFree(Opaque /* ptr */ ); -#define uTypedRecalloc(pO,o,n,t) ((t *)uRecalloc((Opaque)pO,((unsigned)o),((unsigned)n),sizeof(t))) - /***====================================================================***/ extern Boolean uSetErrorFile(char * /* name */ |