Remove duplicated body copying code

Put the name first in the string arena so that the macro body
copying code is identical for both macro setting cases.
This commit is contained in:
Michael Schroeder 2021-11-05 13:08:36 +01:00 committed by Panu Matilainen
parent 263f70b204
commit 48825725e6
1 changed files with 11 additions and 16 deletions

View File

@ -1663,13 +1663,7 @@ static void pushMacroAny(rpmMacroContext mc,
if (mep) {
/* entry with shared name */
me = xmalloc(mesize);
/* copy body */
me->body = p = me->arena;
if (blen)
memcpy(p, b, blen + 1);
else
*p = '\0';
p += blen + 1;
p = me->arena;
/* set name */
me->name = (*mep)->name;
}
@ -1678,18 +1672,19 @@ static void pushMacroAny(rpmMacroContext mc,
mep = newEntry(mc, pos);
size_t nlen = strlen(n);
me = xmalloc(mesize + nlen + 1);
/* copy body */
me->body = p = me->arena;
if (blen)
memcpy(p, b, blen + 1);
else
*p = '\0';
p += blen + 1;
p = me->arena;
/* copy name */
me->name = memcpy(p, n, nlen + 1);
me->name = p;
memcpy(p, n, nlen + 1);
p += nlen + 1;
}
/* copy body */
me->body = p;
if (blen)
memcpy(p, b, blen + 1);
else
*p = '\0';
p += blen + 1;
/* copy options */
if (olen)
me->opts = memcpy(p, o, olen + 1);