From 27ca3038748d9bff81ae72cd19dadb4467e5d1de Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 3 Jul 2017 18:13:15 +0200 Subject: [PATCH] Improve skip_or_save_block Stop at level 0 only for matching outer '}' (which is added). Otherwise stop only at stop tokens (which aren't added). --- tccgen.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tccgen.c b/tccgen.c index 4e0a753..f875e51 100644 --- a/tccgen.c +++ b/tccgen.c @@ -5867,11 +5867,13 @@ static void block(int *bsym, int *csym, int is_expr) } /* This skips over a stream of tokens containing balanced {} and () - pairs, stopping at outer ',' ';' and '}'. If STR then allocates - and stores the skipped tokens in *STR. This doesn't check if - () and {} are nested correctly, i.e. "({)}" is accepted. */ + pairs, stopping at outer ',' ';' and '}' (or matching '}' if we started + with a '{'). If STR then allocates and stores the skipped tokens + in *STR. This doesn't check if () and {} are nested correctly, + i.e. "({)}" is accepted. */ static void skip_or_save_block(TokenString **str) { + int braces = tok == '{'; int level = 0; if (str) *str = tok_str_alloc(); @@ -5892,7 +5894,7 @@ static void skip_or_save_block(TokenString **str) level++; } else if (t == '}' || t == ')') { level--; - if (level == 0) + if (level == 0 && braces && t == '}') break; } } @@ -6413,9 +6415,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, But GNU C supports it, so we need to recurse even into subfields of structs and arrays when size_only is set. */ /* just skip expression */ - do { - skip_or_save_block(NULL); - } while (tok != '}' && tok != ',' && tok != -1); + skip_or_save_block(NULL); } else { if (!have_elem) { /* This should happen only when we haven't parsed