Skip to content

Commit 216a95b

Browse files
committed
Merge pull request #165 from sparkprime/underflow
Fix another underflow in strip_ws
2 parents ef3fef8 + a513d6a commit 216a95b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

core/lexer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ static std::string strip_ws(const std::string &s, unsigned margin)
3232
size_t i = 0;
3333
while (i < s.length() && (s[i] == ' ' || s[i] == '\t' || s[i] == '\r') && i < margin)
3434
i++;
35-
size_t j = s.size() - 1;
36-
while (j >= i && (s[j] == ' ' || s[j] == '\t' || s[j] == '\r'))
35+
size_t j = s.size();
36+
while (j > i && (s[j - 1] == ' ' || s[j - 1] == '\t' || s[j - 1] == '\r')) {
3737
j--;
38-
return std::string(&s[i], &s[j+1]);
38+
}
39+
return std::string(&s[i], &s[j]);
3940
}
4041

4142
/** Split a string by \n and also strip left (up to margin) & right whitespace from each line. */

0 commit comments

Comments
 (0)