public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [pushed] Fix crash in gdb_rl_callback_handler
@ 2024-04-15 18:53 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2024-04-15 18:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

commit bdcd50f9 ("Strip trailing newlines from input string")
introduced a crash in eof-exit.exp.  This patch fixes the problem by
adding a NULL check in the appropriate spot.

Regression tested on x86-64 Fedora 38.  I'm checking this in.
---
 gdb/event-top.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/gdb/event-top.c b/gdb/event-top.c
index f0c07ba7f64..6a2a75fe3dc 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -254,10 +254,13 @@ gdb_rl_callback_handler (char *rl) noexcept
   /* In bracketed paste mode, pasting a complete line can result in a
      literal newline appearing at the end of LINE.  However, we never
      want this in gdb.  */
-  size_t len = strlen (rl);
-  while (len > 0 && (rl[len - 1] == '\r' || rl[len - 1] == '\n'))
-    --len;
-  rl[len] = '\0';
+  if (rl != nullptr)
+    {
+      size_t len = strlen (rl);
+      while (len > 0 && (rl[len - 1] == '\r' || rl[len - 1] == '\n'))
+	--len;
+      rl[len] = '\0';
+    }
 
   try
     {
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-15 18:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-15 18:53 [pushed] Fix crash in gdb_rl_callback_handler Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).