Skip to content

Commit cf448fc

Browse files
committed
fix #12379 - FN: uninitvar due to line splicing
1 parent 2bbb496 commit cf448fc

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

simplecpp.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,35 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
788788
while (stream.good() && ch != '\r' && ch != '\n') {
789789
currentToken += ch;
790790
ch = stream.readChar();
791+
if(ch == '\\') {
792+
TokenString tmp;
793+
char tmp_ch = ch;
794+
while((stream.good()) && (tmp_ch == '\\')) {
795+
tmp += tmp_ch;
796+
tmp_ch = stream.readChar();
797+
}
798+
if(!stream.good()) {
799+
if(!tmp.empty()) {
800+
currentToken += tmp;
801+
}
802+
break;
803+
}
804+
805+
if(tmp_ch != '\r' && tmp_ch != '\n') {
806+
currentToken += tmp;
807+
} else {
808+
while((stream.good()) && (tmp_ch == '\r' || tmp_ch == '\n')) {
809+
currentToken += tmp_ch;
810+
tmp_ch = stream.readChar();
811+
}
812+
if(!stream.good()) {
813+
break;
814+
}
815+
}
816+
817+
ch = tmp_ch;
818+
continue;
819+
}
791820
}
792821
const std::string::size_type pos = currentToken.find_last_not_of(" \t");
793822
if (pos < currentToken.size() - 1U && currentToken[pos] == '\\')

test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ static void comment_multiline()
434434
const char code[] = "#define ABC {// \\\n"
435435
"}\n"
436436
"void f() ABC\n";
437-
ASSERT_EQUALS("\n\nvoid f ( ) { }", preprocess(code));
437+
ASSERT_EQUALS("\n\nvoid f ( ) {", preprocess(code));
438438
}
439439

440440

0 commit comments

Comments
 (0)