Skip to content

Commit

Permalink
Clean up shescape macro implementation
Browse files Browse the repository at this point in the history
Realizing that we have dynamic string buffer available in the macro
engine... so we don't need a dumb worst case malloc and all the other
crap in the old tag format era implementation.
  • Loading branch information
pmatilai authored and ffesti committed Oct 8, 2021
1 parent 470498b commit 5e97c0a
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions rpmio/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -1147,24 +1147,15 @@ static size_t doVerbose(MacroBuf mb, rpmMacroEntry me, ARGV_t argv)

static size_t doShescape(MacroBuf mb, rpmMacroEntry me, ARGV_t argv)
{
char *result, *dst;
const char *src = argv[1];

result = dst = xmalloc(strlen(src) * 4 + 3);
*dst++ = '\'';
for (; *src != '\0'; src++) {
if (*src == '\'') {
*dst++ = '\'';
*dst++ = '\\';
*dst++ = '\'';
*dst++ = '\'';
mbAppend(mb, '\'');
for (const char *s = argv[1]; *s != '\0'; s++) {
if (*s == '\'') {
mbAppendStr(mb, "'\\''");
} else {
*dst++ = *src;
mbAppend(mb, *s);
}
}
*dst++ = '\'';
*dst = '\0';
mbAppendStr(mb, result);
mbAppend(mb, '\'');
return 0;
}

Expand Down

0 comments on commit 5e97c0a

Please sign in to comment.