File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -117,20 +117,21 @@ uint32_t swift::validateUTF8CharacterAndAdvance(const char *&Ptr,
117117 if (CurByte < 0x80 )
118118 return CurByte;
119119
120- // Read the number of high bits set, which indicates the number of bytes in
121- // the character.
122- unsigned EncodedBytes = CLO8 (CurByte);
123-
124- // If this is 0b10XXXXXX, then it is a continuation character.
125- if (EncodedBytes == 1 ||
126- !isStartOfUTF8Character (CurByte)) {
120+ // If this is not the start of a UTF8 character,
121+ // then it is either a continuation byte or an invalid UTF8 code point.
122+ if (!isStartOfUTF8Character (CurByte)) {
127123 // Skip until we get the start of another character. This is guaranteed to
128124 // at least stop at the nul at the end of the buffer.
129125 while (Ptr < End && !isStartOfUTF8Character (*Ptr))
130126 ++Ptr;
131127 return ~0U ;
132128 }
133129
130+ // Read the number of high bits set, which indicates the number of bytes in
131+ // the character.
132+ unsigned EncodedBytes = CLO8 (CurByte);
133+ assert ((EncodedBytes >= 2 && EncodedBytes <= 4 ));
134+
134135 // Drop the high bits indicating the # bytes of the result.
135136 unsigned CharValue = (unsigned char )(CurByte << EncodedBytes) >> EncodedBytes;
136137
You can’t perform that action at this time.
0 commit comments