From e490a3c6e91efd653d3a314aad376286391bb5d1 Mon Sep 17 00:00:00 2001 From: Xusheng Date: Thu, 26 Feb 2026 15:45:03 +0800 Subject: [PATCH] Fix crash when architecture string has no hyphen after colon When connecting to QEMU-PPC targets, the architecture string may be "powerpc:common" which contains a colon but no hyphen. The code was calling string::replace() with the result of string::find('-') without checking if find() returned npos, causing a crash. This fix adds a check for npos before calling replace() in all three affected adapter files. Fixes #1000 Co-Authored-By: Claude Opus 4.5 --- core/adapters/corelliumadapter.cpp | 4 +++- core/adapters/esrevenadapter.cpp | 4 +++- core/adapters/gdbadapter.cpp | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/adapters/corelliumadapter.cpp b/core/adapters/corelliumadapter.cpp index 5a731660..1b74a531 100644 --- a/core/adapters/corelliumadapter.cpp +++ b/core/adapters/corelliumadapter.cpp @@ -137,7 +137,9 @@ bool CorelliumAdapter::LoadRegisterInfo() if (architecture.find(':') != std::string::npos) { architecture.erase(0, architecture.find(':') + 1); - architecture.replace(architecture.find('-'), 1, "_"); + auto hyphenPos = architecture.find('-'); + if (hyphenPos != std::string::npos) + architecture.replace(hyphenPos, 1, "_"); } m_remoteArch = architecture; diff --git a/core/adapters/esrevenadapter.cpp b/core/adapters/esrevenadapter.cpp index ef71a2bd..ea137974 100644 --- a/core/adapters/esrevenadapter.cpp +++ b/core/adapters/esrevenadapter.cpp @@ -160,7 +160,9 @@ bool EsrevenAdapter::LoadRegisterInfo() if (architecture.find(':') != std::string::npos) { architecture.erase(0, architecture.find(':') + 1); - architecture.replace(architecture.find('-'), 1, "_"); + auto hyphenPos = architecture.find('-'); + if (hyphenPos != std::string::npos) + architecture.replace(hyphenPos, 1, "_"); } m_remoteArch = architecture; diff --git a/core/adapters/gdbadapter.cpp b/core/adapters/gdbadapter.cpp index bbc8a534..6babf4f3 100644 --- a/core/adapters/gdbadapter.cpp +++ b/core/adapters/gdbadapter.cpp @@ -160,7 +160,9 @@ bool GdbAdapter::LoadRegisterInfo() if (architecture.find(':') != std::string::npos) { architecture.erase(0, architecture.find(':') + 1); - architecture.replace(architecture.find('-'), 1, "_"); + auto hyphenPos = architecture.find('-'); + if (hyphenPos != std::string::npos) + architecture.replace(hyphenPos, 1, "_"); } m_remoteArch = architecture;