]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add null check for character type name
authorTom Tromey <tromey@adacore.com>
Tue, 3 Feb 2026 20:03:45 +0000 (13:03 -0700)
committerTom Tromey <tromey@adacore.com>
Wed, 4 Feb 2026 18:16:06 +0000 (11:16 -0700)
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.

gdb/char-print.c

index 2d9a43618c920658494a16831ec297d67411b423..7efc09af6eff7050f4e857d2bb03826149b43ee1 100644 (file)
@@ -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)
     {