1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-03 17:37:18 +00:00

Handle non-ASCII characters while saving without triggering an assertion

This commit is contained in:
Evil Eye 2021-11-09 21:45:16 +01:00
parent 29847655f6
commit 8f48a1f030
3 changed files with 14 additions and 4 deletions

View File

@ -75,6 +75,7 @@
Bug #6363: Some scripts in Morrowland fail to work Bug #6363: Some scripts in Morrowland fail to work
Bug #6376: Creatures should be able to use torches Bug #6376: Creatures should be able to use torches
Bug #6386: Artifacts in water reflection due to imprecise screen-space coordinate computation Bug #6386: Artifacts in water reflection due to imprecise screen-space coordinate computation
Bug #6396: Inputting certain Unicode characters triggers an assertion
Bug #6416: Morphs are applied to the wrong target Bug #6416: Morphs are applied to the wrong target
Feature #890: OpenMW-CS: Column filtering Feature #890: OpenMW-CS: Column filtering
Feature #2554: Modifying an object triggers the instances table to scroll to the corresponding record Feature #2554: Modifying an object triggers the instances table to scroll to the corresponding record

View File

@ -8,6 +8,8 @@
#include <components/esm/esmreader.hpp> #include <components/esm/esmreader.hpp>
#include <components/esm/defs.hpp> #include <components/esm/defs.hpp>
#include <components/misc/utf8stream.hpp>
bool MWState::operator< (const Slot& left, const Slot& right) bool MWState::operator< (const Slot& left, const Slot& right)
{ {
return left.mTimeStamp<right.mTimeStamp; return left.mTimeStamp<right.mTimeStamp;
@ -52,12 +54,14 @@ void MWState::Character::addSlot (const ESM::SavedGame& profile)
std::ostringstream stream; std::ostringstream stream;
// The profile description is user-supplied, so we need to escape the path // The profile description is user-supplied, so we need to escape the path
for (std::string::const_iterator it = profile.mDescription.begin(); it != profile.mDescription.end(); ++it) Utf8Stream description(profile.mDescription);
while(!description.eof())
{ {
if (std::isalnum(*it)) // Ignores multibyte characters and non alphanumeric characters auto c = description.consume();
stream << *it; if(c > 0 && c <= 0x7F && std::isalnum(c)) // Ignore multibyte characters and non alphanumeric characters
stream << static_cast<char>(c);
else else
stream << "_"; stream << '_';
} }
const std::string ext = ".omwsave"; const std::string ext = ".omwsave";

View File

@ -30,6 +30,11 @@ public:
{ {
} }
Utf8Stream (const std::string& str) :
Utf8Stream (reinterpret_cast<Point>(str.c_str()), reinterpret_cast<Point>(str.c_str() + str.size()))
{
}
bool eof () const bool eof () const
{ {
return cur == end; return cur == end;