Skip to content

Commit 6635c5b

Browse files
committed
fixed handling of incomplete UTF-8 BOM 0xefbbbf
1 parent 9012b67 commit 6635c5b

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
@@ -313,7 +313,8 @@ class simplecpp::TokenList::Stream {
313313

314314
// The UTF-16 BOM is 0xfffe or 0xfeff.
315315
if (ch1 >= 0xfe) {
316-
const unsigned short bom = (static_cast<unsigned char>(get()) << 8);
316+
(void)get();
317+
const unsigned short bom = (static_cast<unsigned char>(ch1) << 8);
317318
if (peek() >= 0xfe)
318319
return bom | static_cast<unsigned char>(get());
319320
unget();
@@ -323,12 +324,15 @@ class simplecpp::TokenList::Stream {
323324
// Skip UTF-8 BOM 0xefbbbf
324325
if (ch1 == 0xef) {
325326
(void)get();
326-
if (get() == 0xbb && peek() == 0xbf) {
327+
if (peek() == 0xbb) {
327328
(void)get();
328-
} else {
329-
unget();
329+
if (peek() == 0xbf) {
330+
(void)get();
331+
return 0;
332+
}
330333
unget();
331334
}
335+
unget();
332336
}
333337

334338
return 0;

0 commit comments

Comments
 (0)