fixing double-free in initialzied string arrays, using them in the testcase

This commit is contained in:
Wolfgang Bumiller 2013-06-12 15:53:07 +02:00
parent b30368f026
commit 2c59385633
3 changed files with 12 additions and 6 deletions

View file

@ -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) 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)) { if (!parser_next(parser)) {
parseerror(parser, "parse error in array initializer"); parseerror(parser, "parse error in array initializer");
return false; return false;
} }
size_t i = 0;
while (parser->tok != '}') { while (parser->tok != '}') {
ast_value *v = (ast_value*)parse_expression_leave(parser, true, false, false); ast_value *v = (ast_value*)parse_expression_leave(parser, true, false, false);
if (!v) if (!v)
@ -5232,6 +5237,10 @@ static bool parse_array(parser_t *parser, ast_value *array)
return false; return false;
} }
vec_push(array->initlist, v->constval); 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); ast_unref(v);
if (parser->tok == '}') if (parser->tok == '}')
break; break;

View file

@ -4,4 +4,4 @@ T: -execute
C: -std=fteqcc C: -std=fteqcc
M: 10 20 30 40 50 60 70 M: 10 20 30 40 50 60 70
M: 100 200 300 400 500 600 0 M: 100 200 300 400 500 600 0
M: 1 2 3 M: Hello World

View file

@ -1,6 +1,6 @@
float glob1[7] = { 10, 20, 30, 40, 50, 60, 70 }; float glob1[7] = { 10, 20, 30, 40, 50, 60, 70 };
float glob2[7] = { 100, 200, 300, 400, 500, 600 }; float glob2[7] = { 100, 200, 300, 400, 500, 600 };
float globs[] = { 1, 2, 3 }; string globs[] = { "Hello ", "World" };
void main() { void main() {
float i; float i;
@ -14,8 +14,5 @@ void main() {
print(" ", ftos(glob2[i])); print(" ", ftos(glob2[i]));
print("\n"); print("\n");
print(ftos(globs[0])); print(globs[0], globs[1], "\n");
for (i = 1; i != 3; ++i)
print(" ", ftos(globs[i]));
print("\n");
} }