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,
117
117
if (CurByte < 0x80 )
118
118
return CurByte;
119
119
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)) {
127
123
// Skip until we get the start of another character. This is guaranteed to
128
124
// at least stop at the nul at the end of the buffer.
129
125
while (Ptr < End && !isStartOfUTF8Character (*Ptr))
130
126
++Ptr;
131
127
return ~0U ;
132
128
}
133
129
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
+
134
135
// Drop the high bits indicating the # bytes of the result.
135
136
unsigned CharValue = (unsigned char )(CurByte << EncodedBytes) >> EncodedBytes;
136
137
You can’t perform that action at this time.
0 commit comments