Clarify the macro entry struct a bit
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 4 Apr 2013 08:22:22 +0000 (11:22 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 7 Jun 2013 07:35:44 +0000 (10:35 +0300)
- Macro name, opts and body must not be freed or otherwise written
  to after initialization, make them const pointers to clarify
  (and enforce) this. Arena is used to store whatever we need: it
  always contains the macro body, sometimes also name and/or opts,
  but these can be pointers to elsewhere too.
(cherry picked from commit a944143cf54fb5f41b18949a9c6324d22f382274)

rpmio/macro.c

index 39e93ef..4979a47 100644 (file)
@@ -37,11 +37,12 @@ extern int optind;
 /*! The structure used to store a macro. */
 struct rpmMacroEntry_s {
     struct rpmMacroEntry_s *prev;/*!< Macro entry stack. */
-    char *name;        /*!< Macro name. */
-    char *opts;        /*!< Macro parameters (a la getopt) */
+    const char *name;          /*!< Macro name. */
+    const char *opts;          /*!< Macro parameters (a la getopt) */
+    const char *body;  /*!< Macro body. */
     int used;           /*!< No. of expansions. */
     int level;          /*!< Scoping level. */
-    char body[];       /*!< Macro body. */
+    char arena[];      /*!< String arena. */
 };
 
 /*! The structure used to store the set of macros in a context. */
@@ -1281,7 +1282,7 @@ addMacro(rpmMacroContext mc,
        /* entry with shared name */
        me = xmalloc(mesize);
        /* copy body */
-       p = me->body;
+       me->body = p = me->arena;
        if (blen)
            memcpy(p, b, blen + 1);
        else
@@ -1305,7 +1306,7 @@ addMacro(rpmMacroContext mc,
        size_t nlen = strlen(n);
        me = xmalloc(mesize + nlen + 1);
        /* copy body */
-       p = me->body;
+       me->body = p = me->arena;
        if (blen)
            memcpy(p, b, blen + 1);
        else