Fix conversion to UTF8 for ESM4 Reader strings

toUtf8 returns a string view to the input when input string is ASCII and nothing
is written to the buffer which means output string of Reader::getStringImpl is
not modified.

Move input to the output string and resize it in this case.
crashfix_debugdraw
elsid 2 years ago
parent 80d52e3da8
commit 4f7dcd5ae5
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -652,7 +652,12 @@ bool Reader::getStringImpl(std::string& str, std::size_t size,
stream.read(input.data(), size);
if (stream.gcount() == static_cast<std::streamsize>(size))
{
encoder->getUtf8(input, ToUTF8::BufferAllocationPolicy::FitToRequiredSize, str);
const std::string_view result = encoder->getUtf8(input, ToUTF8::BufferAllocationPolicy::FitToRequiredSize, str);
if (str.empty() && !result.empty())
{
str = std::move(input);
str.resize(result.size());
}
return true;
}
}

Loading…
Cancel
Save