Skip to content

Commit 5fb149d

Browse files
committed
fixed handling of incomplete UTF-8 BOM 0xefbbbf
1 parent 1f32390 commit 5fb149d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

simplecpp.cpp

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

312312
// The UTF-16 BOM is 0xfffe or 0xfeff.
313313
if (ch1 >= 0xfe) {
314-
const unsigned short bom = (static_cast<unsigned char>(get()) << 8);
314+
(void)get();
315+
const unsigned short bom = (static_cast<unsigned char>(ch1) << 8);
315316
if (peek() >= 0xfe)
316317
return bom | static_cast<unsigned char>(get());
317318
unget();
@@ -321,12 +322,15 @@ class simplecpp::TokenList::Stream {
321322
// Skip UTF-8 BOM 0xefbbbf
322323
if (ch1 == 0xef) {
323324
(void)get();
324-
if (get() == 0xbb && peek() == 0xbf) {
325+
if (peek() == 0xbb) {
325326
(void)get();
326-
} else {
327-
unget();
327+
if (peek() == 0xbf) {
328+
(void)get();
329+
return 0;
330+
}
328331
unget();
329332
}
333+
unget();
330334
}
331335

332336
return 0;

0 commit comments

Comments
 (0)