]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
parser_strdup to wrap util_strdup and actually dup empty strings
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 10:26:21 +0000 (12:26 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 10:26:21 +0000 (12:26 +0200)
parser.c

index 91c43f4595f10e03f0d58e01934238cceb5341e6..89edf87e1aa46c3c66e6621341e76808f69e5bec 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -171,6 +171,17 @@ ast_value* parser_const_float_0(parser_t *parser)
     return parser->imm_float_zero;
 }
 
+char *parser_strdup(const char *str)
+{
+    if (str && !*str) {
+        /* actually dup empty strings */
+        char *out = mem_a(1);
+        *out = 0;
+        return out;
+    }
+    return util_strdup(str);
+}
+
 ast_value* parser_const_string(parser_t *parser, const char *str)
 {
     size_t i;
@@ -181,7 +192,7 @@ ast_value* parser_const_string(parser_t *parser, const char *str)
     }
     out = ast_value_new(parser_ctx(parser), "#IMMEDIATE", TYPE_STRING);
     out->isconst = true;
-    out->constval.vstring = util_strdup(str);
+    out->constval.vstring = parser_strdup(str);
     if (!parser_t_imm_string_add(parser, out)) {
         ast_value_delete(out);
         return NULL;