From bd531ec1fde7d47f71c8d68c44ba3f79ae148564 Mon Sep 17 00:00:00 2001 From: seyko Date: Mon, 23 Mar 2015 08:27:16 +0300 Subject: A right fix for the array in struct initialization w/o '{' Parse a type if there is only one '(' before a type token. Otherwise a recursion will perform a job. --- tccgen.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'tccgen.c') diff --git a/tccgen.c b/tccgen.c index 39d4566..2478d4e 100644 --- a/tccgen.c +++ b/tccgen.c @@ -5546,33 +5546,26 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, s->c = array_length; } else if ((type->t & VT_BTYPE) == VT_STRUCT && (sec || !first || tok == '{')) { - int par_count; /* NOTE: the previous test is a specific case for automatic struct/union init */ /* XXX: union needs only one init */ - /* XXX: this test is incorrect for local initializers - beginning with ( without {. It would be much more difficult - to do it correctly (ideally, the expression parser should - be used in all cases) */ - par_count = 0; if (tok == '(') { AttributeDef ad1; CType type1; next(); - while (tok == '(') { - par_count++; - next(); - } - if (!parse_btype(&type1, &ad1)) - expect("cast"); - type_decl(&type1, &ad1, &n, TYPE_ABSTRACT); + if (tok != '(') { + if (!parse_btype(&type1, &ad1)) + expect("cast"); + type_decl(&type1, &ad1, &n, TYPE_ABSTRACT); #if 0 - if (!is_assignable_types(type, &type1)) - tcc_error("invalid type for cast"); + if (!is_assignable_types(type, &type1)) + tcc_error("invalid type for cast"); #endif - skip(')'); + skip(')'); + } else + unget_tok(tok); } no_oblock = 1; if (first || tok == '{') { @@ -5646,10 +5639,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, } if (!no_oblock) skip('}'); - while (par_count) { - skip(')'); - par_count--; - } } else if (tok == '{') { next(); decl_initializer(type, sec, c, first, size_only); -- cgit v1.3.1