From: Tom Tromey Date: Sat, 20 Sep 2025 20:02:53 +0000 (-0600) Subject: Fix test in anonymous_struct_prefix X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8bbc7f91fc5c59281b4fa790185d7562b20a5e18;p=thirdparty%2Fbinutils-gdb.git Fix test in anonymous_struct_prefix I noticed a bad test in dwarf2/read.c:anonymous_struct_prefix: attr = dw2_linkage_name_attr (die, cu); const char *attr_name = attr->as_string (); if (attr == NULL || attr_name == NULL) return NULL; Here, if attr==NULL, this will crash before the test can be executed. This patch fixes the problem by hoisting the test. I'm checking this in as obvious. --- diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index bc8b0883ed2..801917937ec 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -17048,9 +17048,11 @@ anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) return NULL; attr = dw2_linkage_name_attr (die, cu); + if (attr == nullptr) + return nullptr; const char *attr_name = attr->as_string (); - if (attr == NULL || attr_name == NULL) - return NULL; + if (attr_name == nullptr) + return nullptr; /* dwarf2_name had to be already called. */ gdb_assert (attr->canonical_string_p ());