From 14dd441c5b6f2a4303ae128883469f4f09dbc32b Mon Sep 17 00:00:00 2001 From: Rob Shearman Date: Fri, 25 Apr 2008 10:58:40 +0100 Subject: [PATCH] widl: Make the rules for parsing fields in structures, encapsulated unions and non-encapsulated unions more strict. Move the rules in fields that handle empty union cases into separate union rules so that they can't erroneously be accepted for structures or other types of unions. --- tools/widl/parser.y | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 461483cc0a6..1732eaec018 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -287,8 +287,8 @@ static statement_list_t *append_statement(statement_list_t *list, statement_t *s %type type %type coclass_int %type coclass_ints -%type arg field s_field case enum constdef externdef -%type m_args no_args args fields cases enums enum_list dispint_props +%type arg field ne_union_field union_field s_field case enum constdef externdef +%type m_args no_args args fields ne_union_fields cases enums enum_list dispint_props %type m_ident t_ident ident %type declarator func_declarator direct_declarator %type declarator_list @@ -576,11 +576,11 @@ cases: { $$ = NULL; } | cases case { $$ = append_var( $1, $2 ); } ; -case: tCASE expr_const ':' field { attr_t *a = make_attrp(ATTR_CASE, append_expr( NULL, $2 )); +case: tCASE expr_const ':' union_field { attr_t *a = make_attrp(ATTR_CASE, append_expr( NULL, $2 )); $$ = $4; if (!$$) $$ = make_var(NULL); $$->attrs = append_attr( $$->attrs, a ); } - | tDEFAULT ':' field { attr_t *a = make_attr(ATTR_DEFAULT); + | tDEFAULT ':' union_field { attr_t *a = make_attr(ATTR_DEFAULT); $$ = $3; if (!$$) $$ = make_var(NULL); $$->attrs = append_attr( $$->attrs, a ); } @@ -707,10 +707,20 @@ fields: { $$ = NULL; } field: s_field ';' { $$ = $1; } | m_attributes uniondef ';' { $$ = make_var(NULL); $$->type = $2; $$->attrs = $1; } + ; + +ne_union_field: + s_field ';' { $$ = $1; } | attributes ';' { $$ = make_var(NULL); $$->attrs = $1; } - | ';' { $$ = NULL; } + +ne_union_fields: { $$ = NULL; } + | ne_union_fields ne_union_field { $$ = append_var( $1, $2 ); } ; +union_field: + s_field ';' { $$ = $1; } + | ';' { $$ = NULL; } + s_field: m_attributes type declarator { $$ = $3->var; $$->attrs = check_field_attrs($$->name, $1); set_type($$, $2, $3, FALSE); @@ -990,7 +1000,8 @@ typedef: tTYPEDEF m_attributes type declarator_list } ; -uniondef: tUNION t_ident '{' fields '}' { $$ = get_typev(RPC_FC_NON_ENCAPSULATED_UNION, $2, tsUNION); +uniondef: tUNION t_ident '{' ne_union_fields '}' + { $$ = get_typev(RPC_FC_NON_ENCAPSULATED_UNION, $2, tsUNION); $$->kind = TKIND_UNION; $$->fields_or_args = $4; $$->defined = TRUE; -- 2.11.4.GIT