From 2c66d4d3a2c7b9b6c74f38c8a4ef847f4e624740 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 22 Dec 2021 20:43:44 +0100 Subject: [PATCH] Optimize the check --- code/Common/BaseImporter.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index 570ba7f7b..82b8f12fc 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -372,16 +372,14 @@ void BaseImporter::ConvertToUTF8(std::vector &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); } }