[binutils-gdb] Fix test in anonymous_struct_prefix

Tom Tromey tromey@sourceware.org
Sat Sep 20 20:09:09 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8bbc7f91fc5c59281b4fa790185d7562b20a5e18

commit 8bbc7f91fc5c59281b4fa790185d7562b20a5e18
Author: Tom Tromey <tom@tromey.com>
Date:   Sat Sep 20 14:02:53 2025 -0600

    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:
---
 gdb/dwarf2/read.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

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 ());


More information about the Gdb-cvs mailing list