mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-21 19:01:29 +00:00
fixing double-free in initialzied string arrays, using them in the testcase
This commit is contained in:
parent
b30368f026
commit
2c59385633
3 changed files with 12 additions and 6 deletions
9
parser.c
9
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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue