From: Tom Tromey Date: Wed, 14 May 2025 13:59:16 +0000 (-0600) Subject: Add initializers to field_of_this_result X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9f400a2f15c4892537727f75acb5e3b463aa0ea3;p=thirdparty%2Fbinutils-gdb.git Add initializers to field_of_this_result This adds initializers to field_of_this_result, so that certain spots don't have to memset it. This approach seems safer and cleaner. Approved-By: Simon Marchi --- diff --git a/gdb/c-exp.y b/gdb/c-exp.y index f53a1383b72..bdf76744817 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -3042,10 +3042,6 @@ classify_name (struct parser_state *par_state, const struct block *block, std::string copy = copy_name (yylval.sval); - /* Initialize this in case we *don't* use it in this call; that way - we can refer to it unconditionally below. */ - memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this)); - bsym = lookup_symbol (copy.c_str (), block, SEARCH_VFT, par_state->language ()->name_of_this () ? &is_a_field_of_this : NULL); diff --git a/gdb/symtab.c b/gdb/symtab.c index 5147aee55d5..313aa5ffa00 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2163,13 +2163,6 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type, domain_name (domain).c_str (), language_str (language)); } - /* Make sure we do something sensible with is_a_field_of_this, since - the callers that set this parameter to some non-null value will - certainly use it later. If we don't set it, the contents of - is_a_field_of_this are undefined. */ - if (is_a_field_of_this != NULL) - memset (is_a_field_of_this, 0, sizeof (*is_a_field_of_this)); - langdef = language_def (language); /* Search specified block and its superiors. Don't search diff --git a/gdb/symtab.h b/gdb/symtab.h index e547d109f35..0a57be5ed80 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2101,17 +2101,17 @@ struct field_of_this_result symbol was not found in 'this'. If non-NULL, then one of the other fields will be non-NULL as well. */ - struct type *type; + struct type *type = nullptr; /* If the symbol was found as an ordinary field of 'this', then this is non-NULL and points to the particular field. */ - struct field *field; + struct field *field = nullptr; /* If the symbol was found as a function field of 'this', then this is non-NULL and points to the particular field. */ - struct fn_fieldlist *fn_field; + struct fn_fieldlist *fn_field = nullptr; }; /* Find the definition for a specified symbol name NAME