From aba020925db8ec81bf6bd15c767c231302adedbd Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 3 May 2023 17:56:34 +0300 Subject: [PATCH] rosenberg: fully initializing the struct does not clear the holes If the struct is fully initialized then check for struct holes. Signed-off-by: Dan Carpenter --- check_rosenberg.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/check_rosenberg.c b/check_rosenberg.c index 0de6f6cd..204eb40a 100644 --- a/check_rosenberg.c +++ b/check_rosenberg.c @@ -146,15 +146,26 @@ static int has_global_scope(struct expression *expr) static int was_initialized(struct expression *expr) { - struct symbol *sym; + struct symbol *sym, *type; char *name; name = expr_to_var_sym(expr, &sym); if (!name) return 0; - if (sym->initializer) + if (!sym->initializer) + return 0; + type = get_real_base_type(sym); + if (!type) + return 0; + if (type->type != SYM_STRUCT) return 1; - return 0; + + /* Fully initializing a struct does not clear the holes */ + if (ptr_list_size((struct ptr_list *)sym->initializer->expr_list) >= + ptr_list_size((struct ptr_list *)type->symbol_list)) + return 0; + + return 1; } static void match_clear(const char *fn, struct expression *expr, void *_arg_no) -- 2.11.4.GIT