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