Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [pushed] Fix ptid_t selftest crash
Date: Thu,  2 Jul 2026 06:55:34 -0600	[thread overview]
Message-ID: <20260702125534.2381813-1-tromey@adacore.com> (raw)

Sam James pointed out that my recent patch to add ptid_t::parse caused
a selftest crash.

At first I couldn't see why this did not crash for me, but then I
realized that ptid_t::parse didn't unconditionally initialize '*obuf'.
Initializing it to nullptr made this crash reliably.

The underlying bug is that some code paths in ptid_t::parse don't set
obuf on return.  This patch fixes the bug by passing 'obuf' down to
hex_or_minus_one.

Since this is straightforward and fixes a new crash, I'm checking it
in.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34340
---
 gdb/unittests/ptid-selftests.c | 2 +-
 gdbsupport/ptid.cc             | 5 +----
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/gdb/unittests/ptid-selftests.c b/gdb/unittests/ptid-selftests.c
index c02401db952..b52c98cdc54 100644
--- a/gdb/unittests/ptid-selftests.c
+++ b/gdb/unittests/ptid-selftests.c
@@ -154,7 +154,7 @@ static_assert (!ptid_t (2, 2, 2).matches (both),
 static ptid_t
 parse_one (const char *str, bool for_remote)
 {
-  const char *out;
+  const char *out = nullptr;
   ptid_t result = ptid_t::parse (str, &out, for_remote,
     [] ()
       {
diff --git a/gdbsupport/ptid.cc b/gdbsupport/ptid.cc
index 731a5bc3da3..5de1da3ba44 100644
--- a/gdbsupport/ptid.cc
+++ b/gdbsupport/ptid.cc
@@ -119,7 +119,7 @@ ptid_t::parse (const char *buf, const char **obuf, bool for_remote,
     }
 
   /* No multi-process.  Just a thread id.  */
-  hex = hex_or_minus_one (p, &pp, for_remote);
+  hex = hex_or_minus_one (p, obuf, for_remote);
 
   /* Handle special thread ids.  */
   if (hex == (ULONGEST) -1)
@@ -134,8 +134,5 @@ ptid_t::parse (const char *buf, const char **obuf, bool for_remote,
 
   pid = default_pid ();
 
-  if (obuf != nullptr)
-    *obuf = pp;
-
   return ptid_t (pid, lwp);
 }

base-commit: c2d4b5e1135f75f7e4ef7ff68fa899bfe483671b
-- 
2.54.0


                 reply	other threads:[~2026-07-02 12:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260702125534.2381813-1-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox