Skip to content

Commit 14a44eb

Browse files
Fix hang on UTF- 16 LE BOM file
1 parent ae1f0fb commit 14a44eb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

simplecpp.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,10 @@ class simplecpp::TokenList::Stream {
282282
// character is non-ASCII character then replace it with 0xff
283283
if (isUtf16) {
284284
(void)get();
285-
const auto ch2 = static_cast<unsigned char>(peek());
286-
unget();
287-
const int ch16 = makeUtf16Char(ch, ch2);
285+
const int ch2 = peek();
286+
if (ch2 != EOF)
287+
unget();
288+
const int ch16 = makeUtf16Char(ch, static_cast<unsigned char>(ch2));
288289
ch = static_cast<unsigned char>(((ch16 >= 0x80) ? 0xff : ch16));
289290
}
290291

0 commit comments

Comments
 (0)