From: Wolfgang Bumiller Date: Wed, 12 Jun 2013 13:53:07 +0000 (+0200) Subject: fixing double-free in initialzied string arrays, using them in the testcase X-Git-Tag: v0.3.0~142 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2c59385633f0b2304756248b61096f986c9f6c23;p=xonotic%2Fgmqcc.git fixing double-free in initialzied string arrays, using them in the testcase --- diff --git a/parser.c b/parser.c index e6326a9..2b2ebe1 100644 --- 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; diff --git a/tests/arrays.tmpl b/tests/arrays.tmpl index 747a838..38666c4 100644 --- a/tests/arrays.tmpl +++ b/tests/arrays.tmpl @@ -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 diff --git a/tests/arrays2.qc b/tests/arrays2.qc index fc8bdf5..9f0dd10 100644 --- a/tests/arrays2.qc +++ b/tests/arrays2.qc @@ -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"); }