* [pushed] Fix ptid_t selftest crash
@ 2026-07-02 12:55 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2026-07-02 12:55 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-02 12:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-02 12:55 [pushed] Fix ptid_t selftest crash Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox