Split macro name storage out from macro definition struct
authorJeremy Harris <jgh146exb@wizmail.org>
Sat, 8 Jul 2017 12:59:49 +0000 (13:59 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Sat, 8 Jul 2017 12:59:49 +0000 (13:59 +0100)
src/src/exim.c
src/src/readconf.c
src/src/structs.h

index 88e119778cf66ec3ff830bcdcc0daaacc0397d3d..e816fd9c69fc5a40cccb025f43fe69081fc15f57 100644 (file)
@@ -2457,7 +2457,7 @@ for (i = 1; i < argc; i++)
           exit(EXIT_FAILURE);
           }
 
           exit(EXIT_FAILURE);
           }
 
-      m = macro_create(name, s, TRUE, FALSE);
+      m = macro_create(string_copy(name), string_copy(s), TRUE, FALSE);
 
       if (clmacro_count >= MAX_CLMACROS)
         {
 
       if (clmacro_count >= MAX_CLMACROS)
         {
index eb44d1085b2ac7e4881804f8908c2141eb5ba275..e0f9d2ddc8d604150aad77977001cdfcf48c7ae2 100644 (file)
@@ -561,18 +561,21 @@ return US"";
 *       Deal with an assignment to a macro       *
 *************************************************/
 
 *       Deal with an assignment to a macro       *
 *************************************************/
 
-/* We have a new definition. The macro_item structure includes a final vector
-called "name" which is one byte long. Thus, adding "namelen" gives us enough
-room to store the "name" string.
+/* We have a new definition.
 If a builtin macro we place at head of list, else tail.  This lets us lazy-create
 If a builtin macro we place at head of list, else tail.  This lets us lazy-create
-builtins. */
+builtins.
+
+Args:
+ name  Name of the macro.  Must be in storage persistent past the call
+ val   Expansion result for the macro.  Ditto persistence.
+*/
 
 macro_item *
 macro_create(const uschar * name, const uschar * val,
   BOOL command_line, BOOL builtin)
 {
 unsigned namelen = Ustrlen(name);
 
 macro_item *
 macro_create(const uschar * name, const uschar * val,
   BOOL command_line, BOOL builtin)
 {
 unsigned namelen = Ustrlen(name);
-macro_item * m = store_get(sizeof(macro_item) + namelen);
+macro_item * m = store_get(sizeof(macro_item));
 
 /* fprintf(stderr, "%s: '%s' '%s'\n", __FUNCTION__, name, val) */
 if (!macros)
 
 /* fprintf(stderr, "%s: '%s' '%s'\n", __FUNCTION__, name, val) */
 if (!macros)
@@ -594,8 +597,8 @@ else
   }
 m->command_line = command_line;
 m->namelen = namelen;
   }
 m->command_line = command_line;
 m->namelen = namelen;
-m->replacement = string_copy(val);
-Ustrcpy(m->name, name);
+m->name = name;
+m->replacement = val;
 return m;
 }
 
 return m;
 }
 
@@ -689,7 +692,7 @@ if (redef)
 
 /* We have a new definition. */
 else
 
 /* We have a new definition. */
 else
-  (void) macro_create(name, s, FALSE, FALSE);
+  (void) macro_create(string_copy(name), string_copy(s), FALSE, FALSE);
 }
 
 
 }
 
 
index 474b855779b8725809fca9eb6a0285f9d58b9f54..14d109869ec4ceb67972f1e6f2cf4b365d67a6aa 100644 (file)
@@ -28,11 +28,11 @@ struct router_info;
 /* Structure for remembering macros for the configuration file */
 
 typedef struct macro_item {
 /* Structure for remembering macros for the configuration file */
 
 typedef struct macro_item {
-  struct   macro_item *next;
-  BOOL     command_line;
-  unsigned namelen;
-  uschar * replacement;
-  uschar   name[1];
+  struct  macro_item * next;
+  BOOL         command_line;
+  unsigned     namelen;
+  const uschar * name;
+  const uschar * replacement;
 } macro_item;
 
 /* Structure for bit tables for debugging and logging */
 } macro_item;
 
 /* Structure for bit tables for debugging and logging */