]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix crash in f-typeprint.c
authorTom Tromey <tom@tromey.com>
Sat, 13 Sep 2025 19:44:10 +0000 (13:44 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 23 Sep 2025 18:21:38 +0000 (12:21 -0600)
I noticed a crash in f-typeprint.c that was hidden by an xfail:

XFAIL: gdb.fortran/vla-array.exp: print variable length string array type (GDB internal error) (PRMS gcc/101826)

I think this was introduced by commit 6594ca4a ("do not handle a NULL
linebuffer in pager_file::puts") but not detected due to the xfail.

It seems bad for an xfail to cover up a crash but I haven't
investigated that.

Meanwhile, this patch fixes the crash by checking for a NULL pointer
when calling gdb_puts.

Approved-by: Kevin Buettner <kevinb@redhat.com>
gdb/f-typeprint.c

index e96d27c537e8f726dcae490637f7c7d43aa34b48..04eca74fb2bf99a2ec871f0f1c247aa301d1c2c4 100644 (file)
@@ -412,9 +412,11 @@ f_language::f_type_print_base (struct type *type, struct ui_file *stream,
       if (show > 0)
        f_type_print_derivation_info (type, stream);
 
-      gdb_puts (" ", stream);
-
-      gdb_puts (type->name (), stream);
+      if (type->name () != nullptr)
+       {
+         gdb_puts (" ", stream);
+         gdb_puts (type->name (), stream);
+       }
 
       /* According to the definition,
         we only print structure elements in case show > 0.  */
@@ -432,7 +434,8 @@ f_language::f_type_print_base (struct type *type, struct ui_file *stream,
              gdb_puts ("\n", stream);
            }
          gdb_printf (stream, "%*sEnd Type ", level, "");
-         gdb_puts (type->name (), stream);
+         if (type->name () != nullptr)
+           gdb_puts (type->name (), stream);
        }
       break;