mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-22 02:26:11 +00:00
Shell: Correctly auto format command lines consisting of only whitespace
When the command line consists of only whitespace characters, the auto formatter basically tries to trim the trailing whitespace. But due to a subtle bug of decrementing an iterator (which is an unsigned integer) past 0 (or the start of the buffer), that operation resulted in an index out of bounds error and a crash.
This commit is contained in:
parent
9454346341
commit
b6cf62d00a
|
@ -30,8 +30,11 @@ public:
|
|||
return;
|
||||
|
||||
size_t offset = 0;
|
||||
for (auto ptr = m_source.end() - 1; ptr >= m_source.begin() && isspace(*ptr); --ptr)
|
||||
for (auto ptr = m_source.end() - 1; isspace(*ptr); --ptr) {
|
||||
++offset;
|
||||
if (ptr == m_source.begin())
|
||||
break;
|
||||
}
|
||||
|
||||
m_trivia = m_source.substring_view(m_source.length() - offset, offset);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue