Skip to content

Commit c5ebc28

Browse files
alnkpaBillyONeal
authored andcommitted
#1020 handle null bytes when parsing utf8 (#1021)
* add regression test for conversion of null byte * handle null bytes like single byte characters
1 parent be5d43f commit c5ebc28

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Release/src/utilities/asyncrt_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,11 @@ inline size_t count_utf8_to_utf16(const std::string& s)
341341

342342
for (size_t index = 0; index < sSize;)
343343
{
344-
if (sData[index] > 0)
344+
if (sData[index] >= 0)
345345
{
346346
// use fast inner loop to skip single byte code points (which are
347347
// expected to be the most frequent)
348-
while ((++index < sSize) && (sData[index] > 0))
348+
while ((++index < sSize) && (sData[index] >= 0))
349349
;
350350

351351
if (index >= sSize) break;

Release/tests/functional/utils/strings.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ SUITE(strings)
153153
auto result = utility::conversions::utf8_to_utf16(input);
154154
VERIFY_ARE_EQUAL(0x7F, result[0]);
155155

156+
// null byte
157+
input.clear();
158+
input.push_back(0);
159+
input.push_back(0);
160+
result = utility::conversions::utf8_to_utf16(input);
161+
VERIFY_ARE_EQUAL(0, result[0]);
162+
VERIFY_ARE_EQUAL(0, result[1]);
163+
156164
// 2 byte character
157165
input.clear();
158166
// U+80

0 commit comments

Comments
 (0)