[binutils-gdb] Handle -1 in ptid_t::parse

Tom Tromey via Gdb-cvs <[email protected]> Thu, 2 Jul 2026 18:59:07 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d243fb0029e28738abb3f933afbf01e1d0617d74

commit d243fb0029e28738abb3f933afbf01e1d0617d74
Author: Tom Tromey <[email protected]>
Date:   Thu Jul 2 12:12:49 2026 -0600

    Handle -1 in ptid_t::parse
    
    ptid_t::parse fails to correctly handle the -1 return from
    hex_or_minus_one in the 'p' case.  As Mark Wielaard pointed out, it
    does this check:
    
          if (hex != ((unsigned_lwp_type) lwp))
    
    However on 32-bit, this means that it will mishandle (ULONGEST) -1.
    
    This patch fixes the problem by adding a check for the -1 case.
    
    I built a -m32 gdb and verified this fix; I'm checking it in.

Diff:
---
 gdbsupport/ptid.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdbsupport/ptid.cc b/gdbsupport/ptid.cc
index 5de1da3ba44..933e441f9b8 100644
--- a/gdbsupport/ptid.cc
+++ b/gdbsupport/ptid.cc
@@ -109,7 +109,7 @@ ptid_t::parse (const char *buf, const char **obuf, bool for_remote,
 	error (_("invalid remote ptid: %s"), buf);
 
       lwp = (ptid_t::lwp_type) hex;
-      if (hex != ((unsigned_lwp_type) lwp))
+      if (hex != ((unsigned_lwp_type) lwp) && hex != (ULONGEST) -1)
 	error (_("invalid remote ptid: %s"), buf);
 
       if (obuf != nullptr)