[binutils-gdb] Add null check for character type name

Tom Tromey tromey@sourceware.org
Wed Feb 4 18:22:41 GMT 2026


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

commit 4e76b375191934ecf41d27b7d887ce0aa880440c
Author: Tom Tromey <tromey@adacore.com>
Date:   Tue Feb 3 13:03:45 2026 -0700

    Add null check for character type name
    
    The internal AdaCore test suite found that
    wchar_printer::get_default_encoding checks the name of a type without
    first seeing if the name is null:
    
      else if (streq (chtype->name (), "wchar_t"))
    
    Mysteriously, though, this only seems to happen for certain targets
    and perhaps only under certain conditions (I couldn't reproduce it
    msyelf).
    
    I felt that the fix is fairly obvious and that this isn't really worth
    writing a test for.  However I can write one using the DWARF assembler
    if someone feels it is worthwhile.

Diff:
---
 gdb/char-print.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/char-print.c b/gdb/char-print.c
index 2d9a43618c9..7efc09af6ef 100644
--- a/gdb/char-print.c
+++ b/gdb/char-print.c
@@ -127,7 +127,7 @@ wchar_printer::get_default_encoding (type *chtype)
   const char *encoding;
   if (chtype->length () == 1)
     encoding = target_charset (chtype->arch ());
-  else if (streq (chtype->name (), "wchar_t"))
+  else if (chtype->name () != nullptr && streq (chtype->name (), "wchar_t"))
     encoding = target_wide_charset (chtype->arch ());
   else if (chtype->length () == 2)
     {


More information about the Gdb-cvs mailing list