From b82a510f696b8bd6e94c949019b22fdb1a3e49cc Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 28 Nov 2018 13:32:03 +0300 Subject: [PATCH] struct_assignment: handle unions as well I was missing some union assignments. Say you initialized a union to zero then did a copy_from_user(). The user_data information would get set, but smatch_extra still thought that the union members were zero and smatch_extra information trumps user data info. Signed-off-by: Dan Carpenter --- smatch_struct_assignment.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/smatch_struct_assignment.c b/smatch_struct_assignment.c index 90b666fb..a49b9378 100644 --- a/smatch_struct_assignment.c +++ b/smatch_struct_assignment.c @@ -73,9 +73,14 @@ static struct symbol *get_struct_type(struct expression *expr) type = get_type(expr); if (!type) return NULL; - if (type->type == SYM_PTR) + if (type->type == SYM_PTR) { type = get_real_base_type(type); - if (type && type->type == SYM_STRUCT) + if (!type) + return NULL; + } + if (type->type == SYM_STRUCT) + return type; + if (type->type == SYM_UNION) return type; return NULL; } -- 2.11.4.GIT