Skip to content

Commit b370ab8

Browse files
authored
Fix string literal parsing when \\ is on the end (#303)
The issue is that when there is '\\' on the end of the string `expand_string_literal()` function goes out of string range because for loop has a check ```cpp pos < length && (text[pos] != '"' || text[pos-1] == '\\') ``` that is true when '\\' is before last '"' character that cause loop to go beyond it and cause assertion to fail. The current change adds a check if the '\' character before last '"' is not escaped by the former '\' character.
1 parent 396e339 commit b370ab8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

source/lex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ auto expand_string_literal(
380380
// Now we're on the first character of the string itself
381381
for (
382382
;
383-
pos < length && (text[pos] != '"' || text[pos-1] == '\\');
383+
pos < length && (text[pos] != '"' || (text[pos-1] == '\\' && pos>=2 && text[pos-2] != '\\'));
384384
++pos
385385
)
386386
{

0 commit comments

Comments
 (0)