]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix test in anonymous_struct_prefix
authorTom Tromey <tom@tromey.com>
Sat, 20 Sep 2025 20:02:53 +0000 (14:02 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 20 Sep 2025 20:08:19 +0000 (14:08 -0600)
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.

gdb/dwarf2/read.c

index bc8b0883ed2c2e59510efcb487c10d4900468110..801917937ecbcf646cf1a70797a1e3bb135149cc 100644 (file)
@@ -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 ());