Do not require 4byte alignment in isValidUtf8
This commit is contained in:
@@ -105,9 +105,15 @@ T cond_byte_swap(T value) {
|
||||
static bool isValidUtf8(unsigned char *s, size_t length)
|
||||
{
|
||||
for (unsigned char *e = s + length; s != e; ) {
|
||||
if (s + 4 <= e && ((*(uint32_t *) s) & 0x80808080) == 0) {
|
||||
if (s + 4 <= e) {
|
||||
uint32_t tmp;
|
||||
memcpy(&tmp, s, 4);
|
||||
if ((tmp & 0x80808080) == 0) {
|
||||
s += 4;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
while (!(*s & 0x80)) {
|
||||
if (++s == e) {
|
||||
return true;
|
||||
@@ -135,7 +141,6 @@ static bool isValidUtf8(unsigned char *s, size_t length)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user