Skip to content

Commit 572673d

Browse files
committed
fixed handling of incomplete UTF-8 BOM 0xefbbbf
1 parent 81ccfa7 commit 572673d

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

simplecpp.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ class simplecpp::TokenList::Stream {
316316

317317
// The UTF-16 BOM is 0xfffe or 0xfeff.
318318
if (ch1 >= 0xfe) {
319-
const unsigned short bom = (static_cast<unsigned char>(get()) << 8);
319+
(void)get();
320+
const unsigned short bom = (static_cast<unsigned char>(ch1) << 8);
320321
if (peek() >= 0xfe)
321322
return bom | static_cast<unsigned char>(get());
322323
unget();
@@ -326,12 +327,15 @@ class simplecpp::TokenList::Stream {
326327
// Skip UTF-8 BOM 0xefbbbf
327328
if (ch1 == 0xef) {
328329
(void)get();
329-
if (get() == 0xbb && peek() == 0xbf) {
330+
if (peek() == 0xbb) {
330331
(void)get();
331-
} else {
332-
unget();
332+
if (peek() == 0xbf) {
333+
(void)get();
334+
return 0;
335+
}
333336
unget();
334337
}
338+
unget();
335339
}
336340

337341
return 0;

0 commit comments

Comments
 (0)