Simplify / sanitize expandU() a bit
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 27 Sep 2010 11:22:56 +0000 (14:22 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 27 Sep 2010 11:55:12 +0000 (14:55 +0300)
- Instead of saving and restoring the bits we'll mess with, just
  make a temporary expansion state struct with non-buffer state
  copied from "parent".

rpmio/macro.c

index 1c94b3d..b8a9d57 100644 (file)
@@ -444,23 +444,18 @@ expandT(MacroBuf mb, const char * f, size_t flen)
 static int
 expandU(MacroBuf mb, char * u, size_t ulen)
 {
-    size_t tpos = mb->tpos;
-    size_t nb = mb->nb;
-    char *tbuf = mb->buf;
+    struct MacroBuf_s umb;
     int rc;
 
-    /* Force new expansion buffer */
-    mb->buf = NULL;
-    rc = expandMacro(mb, u);
+    /* Copy other state from "parent", but we want a buffer of our own */
+    umb = *mb;
+    umb.buf = NULL;
+    rc = expandMacro(&umb, u);
 
     /* Copy back result, flag error on truncation */
-    rc += (rstrlcpy(u, mb->buf, ulen) >= ulen);
+    rc += (rstrlcpy(u, umb.buf, ulen) >= ulen);
     
-    _free(mb->buf);
-
-    mb->buf = tbuf;
-    mb->tpos = tpos;
-    mb->nb = nb;
+    _free(umb.buf);
 
     return rc;
 }