162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
-
+
|
static int
Invalid(
unsigned char *src) /* Points to lead byte of a UTF-8 byte sequence */
{
unsigned char byte = *src;
int index;
if (byte % 0x04) {
if ((byte & 0xC3) != 0xC0) {
/* Only lead bytes 0xC0, 0xE0, 0xF0, 0xF4 need examination */
return 0;
}
index = (byte - 0xC0) >> 1;
if (src[1] < bounds[index] || src[1] > bounds[index+1]) {
/* Out of bounds - report invalid. */
return 1;
|
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
|
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
|
-
+
|
* before the needs of the lead byte were satisfied.
* Let the (malformed) lead byte alone be a character
*/
return src + 1;
}
next++;
}
if ((next == src + 1) || Invalid((unsigned char *)src)) {
if (Invalid((unsigned char *)src)) {
return src + 1;
}
return next;
}
/*
*---------------------------------------------------------------------------
|