Skip to content

Commit f13de95

Browse files
committed
fixed handling of incomplete UTF-8 BOM 0xefbbbf
1 parent a5db777 commit f13de95

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

315315
// The UTF-16 BOM is 0xfffe or 0xfeff.
316316
if (ch1 >= 0xfe) {
317-
const unsigned short bom = (static_cast<unsigned char>(get()) << 8);
317+
(void)get();
318+
const unsigned short bom = (static_cast<unsigned char>(ch1) << 8);
318319
if (peek() >= 0xfe)
319320
return bom | static_cast<unsigned char>(get());
320321
unget();
@@ -324,12 +325,15 @@ class simplecpp::TokenList::Stream {
324325
// Skip UTF-8 BOM 0xefbbbf
325326
if (ch1 == 0xef) {
326327
(void)get();
327-
if (get() == 0xbb && peek() == 0xbf) {
328+
if (peek() == 0xbb) {
328329
(void)get();
329-
} else {
330-
unget();
330+
if (peek() == 0xbf) {
331+
(void)get();
332+
return 0;
333+
}
331334
unget();
332335
}
336+
unget();
333337
}
334338

335339
return 0;

0 commit comments

Comments
 (0)