]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
fixing double-free in initialzied string arrays, using them in the testcase
authorWolfgang Bumiller <wry.git@bumiller.com>
Wed, 12 Jun 2013 13:53:07 +0000 (15:53 +0200)
committerWolfgang Bumiller <wry.git@bumiller.com>
Wed, 12 Jun 2013 13:53:07 +0000 (15:53 +0200)
parser.c
tests/arrays.tmpl
tests/arrays2.qc

index e6326a9498d3cf259152082c48f31b7c93c1e21f..2b2ebe1b52b15735c81f95df979587df62a839f1 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -5218,10 +5218,15 @@ static bool create_array_accessors(parser_t *parser, ast_value *var)
 
 static bool parse_array(parser_t *parser, ast_value *array)
 {
+    if (array->initlist) {
+        parseerror(parser, "array already initialized elsewhere");
+        return false;
+    }
     if (!parser_next(parser)) {
         parseerror(parser, "parse error in array initializer");
         return false;
     }
+    size_t i = 0;
     while (parser->tok != '}') {
         ast_value *v = (ast_value*)parse_expression_leave(parser, true, false, false);
         if (!v)
@@ -5232,6 +5237,10 @@ static bool parse_array(parser_t *parser, ast_value *array)
             return false;
         }
         vec_push(array->initlist, v->constval);
+        if (v->expression.vtype == TYPE_STRING) {
+            array->initlist[i].vstring = util_strdupe(array->initlist[i].vstring);
+            ++i;
+        }
         ast_unref(v);
         if (parser->tok == '}')
             break;
index 747a838f8cfd7bb6ca14673a107a5c7ed3d05f07..38666c4a514fc1e6e4a3ce0cf5ad1727c97b4d0d 100644 (file)
@@ -4,4 +4,4 @@ T: -execute
 C: -std=fteqcc
 M: 10 20 30 40 50 60 70
 M: 100 200 300 400 500 600 0
-M: 1 2 3
+M: Hello World
index fc8bdf578219399a085838702f8d966a253d1b18..9f0dd10c11a9e542d0e50cda5b2793d7b4037299 100644 (file)
@@ -1,6 +1,6 @@
 float glob1[7] = { 10, 20, 30, 40, 50, 60, 70 };
 float glob2[7] = { 100, 200, 300, 400, 500, 600 };
-float globs[] = { 1, 2, 3 };
+string globs[] = { "Hello ", "World" };
 
 void main() {
     float i;
@@ -14,8 +14,5 @@ void main() {
         print(" ", ftos(glob2[i]));
     print("\n");
 
-    print(ftos(globs[0]));
-    for (i = 1; i != 3; ++i)
-        print(" ", ftos(globs[i]));
-    print("\n");
+    print(globs[0], globs[1], "\n");
 }