From 5bfc8a42eb4106635b934f4231d3eaed1f4ea183 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 9 Jan 2022 21:32:49 +0100 Subject: [PATCH] Handle invalid struct members When something goes wrong when parsing a struct member, e.g. the type does not exist, a nullptr is added to the struct member list. This will cause a crash when iterating over the list. E.g. ``` struct packed { logc x; } s; ``` Add a check so that nullptr members are not added to the list. Signed-off-by: Lars-Peter Clausen --- parse.y | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parse.y b/parse.y index d7c923e13..b00658723 100644 --- a/parse.y +++ b/parse.y @@ -3036,12 +3036,12 @@ struct_data_type struct_union_member_list : struct_union_member_list struct_union_member { std::list*tmp = $1; - tmp->push_back($2); + if ($2) tmp->push_back($2); $$ = tmp; } | struct_union_member { std::list*tmp = new std::list; - tmp->push_back($1); + if ($1) tmp->push_back($1); $$ = tmp; } ;