From 263f70b204433f6d3153c3539dd2c95bf8f5b8c5 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Fri, 5 Nov 2021 13:01:40 +0100 Subject: [PATCH] Split new macro table entry generation into newEntry() No functional changes, just to make the code easier to understand. --- rpmio/macro.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index ff9c0f947..6066b636e 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -195,6 +195,27 @@ findEntry(rpmMacroContext mc, const char *name, size_t namelen, size_t *pos) return NULL; } +/** + * Create a new entry in the macro table. + * @param mc macro context + * @param pos insert position + * @return address of slot in macro table + */ +static rpmMacroEntry * +newEntry(rpmMacroContext mc, size_t pos) +{ + /* extend macro table */ + const int delta = 256; + if (mc->n % delta == 0) + mc->tab = xrealloc(mc->tab, sizeof(rpmMacroEntry) * (mc->n + delta)); + /* shift pos+ entries to the right */ + memmove(mc->tab + pos + 1, mc->tab + pos, sizeof(rpmMacroEntry) * (mc->n - pos)); + mc->n++; + /* make slot */ + mc->tab[pos] = NULL; + return &mc->tab[pos]; +} + /* =============================================================== */ /** @@ -1653,17 +1674,8 @@ static void pushMacroAny(rpmMacroContext mc, me->name = (*mep)->name; } else { - /* extend macro table */ - const int delta = 256; - if (mc->n % delta == 0) - mc->tab = xrealloc(mc->tab, sizeof(me) * (mc->n + delta)); - /* shift pos+ entries to the right */ - memmove(mc->tab + pos + 1, mc->tab + pos, sizeof(me) * (mc->n - pos)); - mc->n++; - /* make slot */ - mc->tab[pos] = NULL; - mep = &mc->tab[pos]; /* entry with new name */ + mep = newEntry(mc, pos); size_t nlen = strlen(n); me = xmalloc(mesize + nlen + 1); /* copy body */