From b1dbdf50af3172ad92ca33a4e6908b63158cba00 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 27 Sep 2010 16:32:15 +0300 Subject: [PATCH] Dynamic expansion buffer reallocation for lua macros too --- rpmio/macro.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index 658bbf624..76bdd69e8 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -475,6 +475,17 @@ static void mbAppend(MacroBuf mb, char c) mb->nb--; } +static void mbAppendStr(MacroBuf mb, const char *str) +{ + size_t len = strlen(str); + if (len > mb->nb) { + mb->buf = xrealloc(mb->buf, mb->tpos + mb->nb + MACROBUFSIZ + len); + mb->nb += MACROBUFSIZ + len; + } + memcpy(mb->buf+mb->tpos, str, len); + mb->tpos += len; + mb->nb -= len; +} /** * Expand output of shell command into target buffer. * @param mb macro expansion state @@ -1239,12 +1250,7 @@ expandMacro(MacroBuf mb, const char *src) rc = 1; printbuf = rpmluaGetPrintBuffer(lua); if (printbuf) { - size_t len = strlen(printbuf); - if (len > mb->nb) - len = mb->nb; - memcpy(mb->buf+mb->tpos, printbuf, len); - mb->tpos += len; - mb->nb -= len; + mbAppendStr(mb, printbuf); } rpmluaSetPrintBuffer(lua, 0); free(scriptbuf);