GeezerVison is showing github.com — fixed handling of incomplete UTF-8 BOM 0xefbbbf · cppcheck-opensource/simplecpp@5fb149d
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: simplecpp.cpp +8-4Lines changed: 8 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -311,7 +311,8 @@ class simplecpp::TokenList::Stream { |
311 | 311 |
|
312 | 312 | // The UTF-16 BOM is 0xfffe or 0xfeff. |
313 | 313 | 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); |
315 | 316 | if (peek() >= 0xfe) |
316 | 317 | return bom | static_cast<unsigned char>(get()); |
317 | 318 | unget(); |
@@ -321,12 +322,15 @@ class simplecpp::TokenList::Stream { |
321 | 322 | // Skip UTF-8 BOM 0xefbbbf |
322 | 323 | if (ch1 == 0xef) { |
323 | 324 | (void)get(); |
324 | | - if (get() == 0xbb && peek() == 0xbf) { |
| 325 | + if (peek() == 0xbb) { |
325 | 326 | (void)get(); |
326 | | - } else { |
327 | | - unget(); |
| 327 | + if (peek() == 0xbf) { |
| 328 | + (void)get(); |
| 329 | + return 0; |
| 330 | + } |
328 | 331 | unget(); |
329 | 332 | } |
| 333 | + unget(); |
330 | 334 | } |
331 | 335 |
|
332 | 336 | return 0; |
|