Skip to content

Commit 9c3d024

Browse files
xusheng6claude
andauthored
Fix crash when architecture string has no hyphen after colon (#1001)
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 <noreply@anthropic.com>
1 parent 5d3a23c commit 9c3d024

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

core/adapters/corelliumadapter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ bool CorelliumAdapter::LoadRegisterInfo()
137137
if (architecture.find(':') != std::string::npos)
138138
{
139139
architecture.erase(0, architecture.find(':') + 1);
140-
architecture.replace(architecture.find('-'), 1, "_");
140+
auto hyphenPos = architecture.find('-');
141+
if (hyphenPos != std::string::npos)
142+
architecture.replace(hyphenPos, 1, "_");
141143
}
142144
m_remoteArch = architecture;
143145

core/adapters/esrevenadapter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ bool EsrevenAdapter::LoadRegisterInfo()
160160
if (architecture.find(':') != std::string::npos)
161161
{
162162
architecture.erase(0, architecture.find(':') + 1);
163-
architecture.replace(architecture.find('-'), 1, "_");
163+
auto hyphenPos = architecture.find('-');
164+
if (hyphenPos != std::string::npos)
165+
architecture.replace(hyphenPos, 1, "_");
164166
}
165167
m_remoteArch = architecture;
166168

core/adapters/gdbadapter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ bool GdbAdapter::LoadRegisterInfo()
160160
if (architecture.find(':') != std::string::npos)
161161
{
162162
architecture.erase(0, architecture.find(':') + 1);
163-
architecture.replace(architecture.find('-'), 1, "_");
163+
auto hyphenPos = architecture.find('-');
164+
if (hyphenPos != std::string::npos)
165+
architecture.replace(hyphenPos, 1, "_");
164166
}
165167
m_remoteArch = architecture;
166168

0 commit comments

Comments
 (0)