mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-19 15:58:56 +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
Notes:
sideshowbarker
2024-07-17 01:11:48 +09:00
Author: https://github.com/ronak69
Commit: b6cf62d00a
Pull-request: https://github.com/SerenityOS/serenity/pull/23746
1 changed files with 4 additions and 1 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue