Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Make pascal_language::print_type handle varstring==nullptr
@ 2024-03-27 16:40 Tom Tromey
  2024-03-28 17:25 ` John Baldwin
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2024-03-27 16:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

PR gdb/31524 points out a crash when pascal_language::print_type is
called with varstring==nullptr.  This crash is a regression arising
from the printf/pager rewrite -- that indirectly removed a NULL check
from gdb's "puts".

This patch instead fixes the problem by adding a check to print_type.
Passing nullptr here seems to be expected in other places (e.g., there
is a call to type_print like this in expprint.c), and other
implementations of this method (or related helpers) explicitly check
for NULL.

I didn't write a test case for this because it seemed like overkill
for a Pascal bug that only occurs with -i=mi.  However, if you want
one, let me know and I will do it.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31524
---
 gdb/p-typeprint.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index 5c48c1400c4..ad98d9ef202 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -54,7 +54,8 @@ pascal_language::print_type (struct type *type, const char *varstring,
       type_print_varspec_prefix (type, stream, show, 0, flags);
     }
   /* first the name */
-  gdb_puts (varstring, stream);
+  if (varstring != nullptr)
+    gdb_puts (varstring, stream);
 
   if ((varstring != NULL && *varstring != '\0')
       && !(code == TYPE_CODE_FUNC
-- 
2.43.0


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

* Re: [PATCH] Make pascal_language::print_type handle varstring==nullptr
  2024-03-27 16:40 [PATCH] Make pascal_language::print_type handle varstring==nullptr Tom Tromey
@ 2024-03-28 17:25 ` John Baldwin
  0 siblings, 0 replies; 2+ messages in thread
From: John Baldwin @ 2024-03-28 17:25 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 3/27/24 12:40 PM, Tom Tromey wrote:
> PR gdb/31524 points out a crash when pascal_language::print_type is
> called with varstring==nullptr.  This crash is a regression arising
> from the printf/pager rewrite -- that indirectly removed a NULL check
> from gdb's "puts".
> 
> This patch instead fixes the problem by adding a check to print_type.
> Passing nullptr here seems to be expected in other places (e.g., there
> is a call to type_print like this in expprint.c), and other
> implementations of this method (or related helpers) explicitly check
> for NULL.
> 
> I didn't write a test case for this because it seemed like overkill
> for a Pascal bug that only occurs with -i=mi.  However, if you want
> one, let me know and I will do it.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31524

Seems obvious to me.  I think it's fine without a test case.

Approved-By: John Baldwin <jhb@FreeBSD.org>

-- 
John Baldwin


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

end of thread, other threads:[~2024-03-28 17:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-27 16:40 [PATCH] Make pascal_language::print_type handle varstring==nullptr Tom Tromey
2024-03-28 17:25 ` John Baldwin

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