Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix crash in f-typeprint.c
@ 2025-09-13 19:48 Tom Tromey
  2025-09-13 21:48 ` Kevin Buettner
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2025-09-13 19:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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

diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index e96d27c537e..65c58b59b2d 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -414,7 +414,8 @@ f_language::f_type_print_base (struct type *type, struct ui_file *stream,
 
       gdb_puts (" ", stream);
 
-      gdb_puts (type->name (), stream);
+      if (type->name () != nullptr)
+	gdb_puts (type->name (), stream);
 
       /* According to the definition,
 	 we only print structure elements in case show > 0.  */
@@ -432,7 +433,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;
 
-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix crash in f-typeprint.c
  2025-09-13 19:48 [PATCH] Fix crash in f-typeprint.c Tom Tromey
@ 2025-09-13 21:48 ` Kevin Buettner
  2025-09-13 22:29   ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Kevin Buettner @ 2025-09-13 21:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

On Sat, 13 Sep 2025 13:48:11 -0600
Tom Tromey <tom@tromey.com> wrote:

> diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
> index e96d27c537e..65c58b59b2d 100644
> --- a/gdb/f-typeprint.c
> +++ b/gdb/f-typeprint.c
> @@ -414,7 +414,8 @@ f_language::f_type_print_base (struct type *type,
> struct ui_file *stream, 
>        gdb_puts (" ", stream);
>  
> -      gdb_puts (type->name (), stream);
> +      if (type->name () != nullptr)
> +	gdb_puts (type->name (), stream);

If you can't print the type, I'm wondering if it makes sense to print
the space before it? (I.e. look at the gdb_puts a few lines above...)

Kevin


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix crash in f-typeprint.c
  2025-09-13 21:48 ` Kevin Buettner
@ 2025-09-13 22:29   ` Tom Tromey
  2025-09-15 16:26     ` Kevin Buettner
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2025-09-13 22:29 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches, Tom Tromey

>>>>> "Kevin" == Kevin Buettner <kevinb@redhat.com> writes:

>> gdb_puts (" ", stream);
>> 
>> -      gdb_puts (type->name (), stream);
>> +      if (type->name () != nullptr)
>> +	gdb_puts (type->name (), stream);

Kevin> If you can't print the type, I'm wondering if it makes sense to print
Kevin> the space before it? (I.e. look at the gdb_puts a few lines above...)

I don't know but this change does preserve what happened before the
change to gdb_puts.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix crash in f-typeprint.c
  2025-09-13 22:29   ` Tom Tromey
@ 2025-09-15 16:26     ` Kevin Buettner
  2025-09-20 20:58       ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Kevin Buettner @ 2025-09-15 16:26 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Sat, 13 Sep 2025 16:29:41 -0600
Tom Tromey <tom@tromey.com> wrote:

> >>>>> "Kevin" == Kevin Buettner <kevinb@redhat.com> writes:  
> 
> >> gdb_puts (" ", stream);
> >> 
> >> -      gdb_puts (type->name (), stream);
> >> +      if (type->name () != nullptr)
> >> +	gdb_puts (type->name (), stream);  
> 
> Kevin> If you can't print the type, I'm wondering if it makes sense to
> Kevin> print the space before it? (I.e. look at the gdb_puts a few lines
> Kevin> above...)  
> 
> I don't know but this change does preserve what happened before the
> change to gdb_puts.

Since it fixes a crash and preserves the original behavior...

Approved-by: Kevin Buettner <kevinb@redhat.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix crash in f-typeprint.c
  2025-09-15 16:26     ` Kevin Buettner
@ 2025-09-20 20:58       ` Tom Tromey
  2025-09-23  0:50         ` Kevin Buettner
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2025-09-20 20:58 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: Tom Tromey, gdb-patches

>> I don't know but this change does preserve what happened before the
>> change to gdb_puts.

Kevin> Since it fixes a crash and preserves the original behavior...

Well, I took another look and I think that moving the space-printing
into the same 'if' seems ok.  It doesn't cause any test regressions
either.

Here's the updated version, let me know what you think.

Tom

commit 2c56513f148f24d9595a8bc95f15acd3e70353d3
Author: Tom Tromey <tom@tromey.com>
Date:   Sat Sep 13 13:44:10 2025 -0600

    Fix crash in f-typeprint.c
    
    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.

diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index e96d27c537e..04eca74fb2b 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -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;
 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix crash in f-typeprint.c
  2025-09-20 20:58       ` Tom Tromey
@ 2025-09-23  0:50         ` Kevin Buettner
  2025-09-23 18:27           ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Kevin Buettner @ 2025-09-23  0:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

On Sat, 20 Sep 2025 14:58:31 -0600
Tom Tromey <tom@tromey.com> wrote:

> >> I don't know but this change does preserve what happened before the
> >> change to gdb_puts.  
> 
> Kevin> Since it fixes a crash and preserves the original behavior...  
> 
> Well, I took another look and I think that moving the space-printing
> into the same 'if' seems ok.  It doesn't cause any test regressions
> either.
> 
> Here's the updated version, let me know what you think.

Yeah, I like this one better.

It still has my approval...

Kevin


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Fix crash in f-typeprint.c
  2025-09-23  0:50         ` Kevin Buettner
@ 2025-09-23 18:27           ` Tom Tromey
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2025-09-23 18:27 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches, Tom Tromey

Kevin> Yeah, I like this one better.

Kevin> It still has my approval...

Thanks.

I'm going to backport this to gdb-17 as well, since it's a regression
with a trivial fix.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-09-23 18:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-13 19:48 [PATCH] Fix crash in f-typeprint.c Tom Tromey
2025-09-13 21:48 ` Kevin Buettner
2025-09-13 22:29   ` Tom Tromey
2025-09-15 16:26     ` Kevin Buettner
2025-09-20 20:58       ` Tom Tromey
2025-09-23  0:50         ` Kevin Buettner
2025-09-23 18:27           ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox