Optimize the check

pull/4282/head
Kim Kulling 2021-12-22 20:43:44 +01:00 committed by GitHub
parent 215f4e1f4d
commit 2c66d4d3a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 7 deletions

View File

@ -372,16 +372,14 @@ void BaseImporter::ConvertToUTF8(std::vector<char> &data) {
}
// UTF 16 BE with BOM
size_t index = 0;
if (*((uint16_t *)&data.front()) == 0xFFFE) {
// Check to ensure no overflow can happen
if(data.size() % 2 != 0) {
return;
}
// swap the endianness ..
for (uint16_t *p = (uint16_t *)&data.front(), *end = (uint16_t *)&data.back(); p <= end; ++p) {
// Check to ensure no overflow can happen
if ((index+2) < data.size()) {
// Swap the data
ByteSwap::Swap2(p);
index += 2;
}
ByteSwap::Swap2(p);
}
}