File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -286,14 +286,15 @@ utf16string __cdecl conversions::utf8_to_utf16(const std::string &s)
286
286
}
287
287
else
288
288
{
289
+ if ((*src & BIT8) != 0 && (*src & BIT7) == 0 )
290
+ {
291
+ throw std::range_error (" UTF-8 string character can never start with 10xxxxxx" );
292
+ }
293
+
289
294
unsigned char numContBytes = 0 ;
290
295
uint32_t codePoint;
291
296
if ((*src & BIT6) == 0 ) // 2 byte character, 0x80 to 0x7FF
292
297
{
293
- if ((*src & BIT8) != 0 && (*src & BIT7) == 0 )
294
- {
295
- throw std::range_error (" UTF-8 string character can never start with 10xxxxxx" );
296
- }
297
298
codePoint = *src & LOW_5BITS;
298
299
numContBytes = 1 ;
299
300
}
@@ -362,8 +363,8 @@ std::string __cdecl conversions::utf16_to_utf8(const utf16string &w)
362
363
// Check for high surrogate.
363
364
if (*src >= H_SURROGATE_START && *src <= H_SURROGATE_END)
364
365
{
365
- const auto highSurrogate = *src;
366
- if (++ src == w.end ())
366
+ const auto highSurrogate = *src++ ;
367
+ if (src == w.end ())
367
368
{
368
369
throw std::range_error (" UTF-16 string is missing low surrogate" );
369
370
}
Original file line number Diff line number Diff line change @@ -256,6 +256,10 @@ TEST(utf8_to_utf16_errors)
256
256
input.push_back (128u ); // 10000000
257
257
input.push_back (128u ); // 10000000
258
258
VERIFY_THROWS (utility::conversions::utf8_to_utf16 (input), std::range_error);
259
+ input.clear ();
260
+ input.push_back (191u ); // 10111111
261
+ input.push_back (128u ); // 10000000
262
+ VERIFY_THROWS (utility::conversions::utf8_to_utf16 (input), std::range_error);
259
263
}
260
264
261
265
TEST (latin1_to_utf16)
You can’t perform that action at this time.
0 commit comments