]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Make pascal_language::print_type handle varstring==nullptr
authorTom Tromey <tom@tromey.com>
Wed, 27 Mar 2024 16:34:46 +0000 (10:34 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 28 Mar 2024 22:28:50 +0000 (16:28 -0600)
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
Approved-By: John Baldwin <jhb@FreeBSD.org>
gdb/p-typeprint.c

index 5c48c1400c4d60c2ba7550a56302c3a21ec49206..ad98d9ef20256409cef17f8ea4b39f598b030ad0 100644 (file)
@@ -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