Skip to content

Commit 5fe7721

Browse files
committed
[lldb] Adjust the for loop condition to prevent unintended increments in ExpandRLE (NFC)
Address the issue reported by static analyser cppcheck regarding missing bounds check for extra iterator increment in a loop. This could lead to accessing out-of-bounds memory. To fix this we have adjusted the loop conditions to not incrementing iterator c there.. Caught by cppcheck - lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp:1300:75: warning: Missing bounds check for extra iterator increment in loop. [StlMissingComparison] Fix #91225
1 parent 1c0063b commit 5fe7721

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ std::string GDBRemoteCommunication::ExpandRLE(std::string packet) {
12971297
// Reserve enough byte for the most common case (no RLE used).
12981298
std::string decoded;
12991299
decoded.reserve(packet.size());
1300-
for (std::string::const_iterator c = packet.begin(); c != packet.end(); ++c) {
1300+
for (std::string::const_iterator c = packet.begin(); c != packet.end();) {
13011301
if (*c == '*') {
13021302
// '*' indicates RLE. Next character will give us the repeat count and
13031303
// previous character is what is to be repeated.
@@ -1316,6 +1316,7 @@ std::string GDBRemoteCommunication::ExpandRLE(std::string packet) {
13161316
} else {
13171317
decoded.push_back(*c);
13181318
}
1319+
c++;
13191320
}
13201321
return decoded;
13211322
}

0 commit comments

Comments
 (0)