From 14a44eb4b9cb5cb1611d4b3ffedb1152ebbf95f0 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 27 Mar 2026 15:18:00 +0100 Subject: [PATCH 1/3] Fix hang on UTF- 16 LE BOM file --- simplecpp.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index 7afc17ab..b63bd0fd 100644 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -282,9 +282,10 @@ class simplecpp::TokenList::Stream { // character is non-ASCII character then replace it with 0xff if (isUtf16) { (void)get(); - const auto ch2 = static_cast(peek()); - unget(); - const int ch16 = makeUtf16Char(ch, ch2); + const int ch2 = peek(); + if (ch2 != EOF) + unget(); + const int ch16 = makeUtf16Char(ch, static_cast(ch2)); ch = static_cast(((ch16 >= 0x80) ? 0xff : ch16)); } From 4cc9e60ff86db4416bbaf1c101808ff3a81a5041 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 27 Mar 2026 16:19:02 +0100 Subject: [PATCH 2/3] Update simplecpp.cpp --- simplecpp.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index b63bd0fd..4baa3728 100644 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -276,16 +276,18 @@ class simplecpp::TokenList::Stream { } unsigned char peekChar() { - auto ch = static_cast(peek()); + const int pk = peek(); + auto ch = static_cast(pk); + if (pk == EOF) + return ch; // For UTF-16 encoded files the BOM is 0xfeff/0xfffe. If the // character is non-ASCII character then replace it with 0xff if (isUtf16) { (void)get(); - const int ch2 = peek(); - if (ch2 != EOF) - unget(); - const int ch16 = makeUtf16Char(ch, static_cast(ch2)); + const int ch2 = static_cast(peek()); + unget(); + const int ch16 = makeUtf16Char(ch, ch2); ch = static_cast(((ch16 >= 0x80) ? 0xff : ch16)); } From b9287529cfaece6702b4eedbfe83f46f6c0c6fe6 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 27 Mar 2026 16:26:49 +0100 Subject: [PATCH 3/3] Update simplecpp.cpp --- simplecpp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index 4baa3728..55264794 100644 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -285,7 +285,7 @@ class simplecpp::TokenList::Stream { // character is non-ASCII character then replace it with 0xff if (isUtf16) { (void)get(); - const int ch2 = static_cast(peek()); + const auto ch2 = static_cast(peek()); unget(); const int ch16 = makeUtf16Char(ch, ch2); ch = static_cast(((ch16 >= 0x80) ? 0xff : ch16));