Skip to content

#1020 handle null bytes when parsing utf8 #1021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Release/src/utilities/asyncrt_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ inline size_t count_utf8_to_utf16(const std::string& s)

for (size_t index = 0; index < sSize;)
{
if (sData[index] > 0)
if (sData[index] >= 0)
{
// use fast inner loop to skip single byte code points (which are
// expected to be the most frequent)
while ((++index < sSize) && (sData[index] > 0))
while ((++index < sSize) && (sData[index] >= 0))
;

if (index >= sSize) break;
Expand Down
8 changes: 8 additions & 0 deletions Release/tests/functional/utils/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ SUITE(strings)
auto result = utility::conversions::utf8_to_utf16(input);
VERIFY_ARE_EQUAL(0x7F, result[0]);

// null byte
input.clear();
input.push_back(0);
input.push_back(0);
result = utility::conversions::utf8_to_utf16(input);
VERIFY_ARE_EQUAL(0, result[0]);
VERIFY_ARE_EQUAL(0, result[1]);

// 2 byte character
input.clear();
// U+80
Expand Down