Stop at level 0 only for matching outer '}' (which is added). Otherwise stop only at stop tokens (which aren't added).
Unified · Split
| @@ -5867,11 +5867,13 @@ static void block(int *bsym, int *csym, int is_expr) · 5866 unmodified lines | ||
| 5867 | 5867 | } |
| 5868 | 5868 | |
| 5869 | 5869 | /* This skips over a stream of tokens containing balanced {} and () |
| 5870 | − pairs, stopping at outer ',' ';' and '}'. If STR then allocates | |
| 5871 | − and stores the skipped tokens in *STR. This doesn't check if | |
| 5872 | − () and {} are nested correctly, i.e. "({)}" is accepted. */ | |
| 5870 | + pairs, stopping at outer ',' ';' and '}' (or matching '}' if we started | |
| 5871 | + with a '{'). If STR then allocates and stores the skipped tokens | |
| 5872 | + in *STR. This doesn't check if () and {} are nested correctly, | |
| 5873 | + i.e. "({)}" is accepted. */ | |
| 5873 | 5874 | static void skip_or_save_block(TokenString **str) |
| 5874 | 5875 | { |
| 5876 | + int braces = tok == '{'; | |
| 5875 | 5877 | int level = 0; |
| 5876 | 5878 | if (str) |
| 5877 | 5879 | *str = tok_str_alloc(); |
| @@ -5892,7 +5894,7 @@ static void skip_or_save_block(TokenString **str) · 14 unmodified lines | ||
| 5892 | 5894 | level++; |
| 5893 | 5895 | } else if (t == '}' || t == ')') { |
| 5894 | 5896 | level--; |
| 5895 | − if (level == 0) | |
| 5897 | + if (level == 0 && braces && t == '}') | |
| 5896 | 5898 | break; |
| 5897 | 5899 | } |
| 5898 | 5900 | } |
| @@ -6413,9 +6415,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 514 unmodified lines | ||
| 6413 | 6415 | But GNU C supports it, so we need to recurse even into |
| 6414 | 6416 | subfields of structs and arrays when size_only is set. */ |
| 6415 | 6417 | /* just skip expression */ |
| 6416 | − do { | |
| 6417 | − skip_or_save_block(NULL); | |
| 6418 | − } while (tok != '}' && tok != ',' && tok != -1); | |
| 6418 | + skip_or_save_block(NULL); | |
| 6419 | 6419 | } else { |
| 6420 | 6420 | if (!have_elem) { |
| 6421 | 6421 | /* This should happen only when we haven't parsed |