1
0
Fork 0

Codechange: do not make a string valid in place, to then copy it

pull/11117/head
Rubidium 2023-07-05 19:36:35 +02:00 committed by rubidium42
parent b958a343fe
commit 18a31cca7c
3 changed files with 5 additions and 10 deletions

View File

@ -2651,12 +2651,9 @@ static ChangeInfoResult LoadTranslationTable(uint gvid, int numinfo, ByteReader
*/ */
static std::string ReadDWordAsString(ByteReader *reader) static std::string ReadDWordAsString(ByteReader *reader)
{ {
char output[5]; std::string output;
for (int i = 0; i < 4; i++) output[i] = reader->ReadByte(); for (int i = 0; i < 4; i++) output.push_back(reader->ReadByte());
output[4] = '\0'; return StrMakeValid(output);
StrMakeValidInPlace(output, lastof(output));
return std::string(output);
} }
/** /**

View File

@ -68,8 +68,7 @@ public:
SlObject(lc, this->GetLoadDescription()); SlObject(lc, this->GetLoadDescription());
if (IsSavegameVersionBefore(SLV_STRING_GAMELOG)) { if (IsSavegameVersionBefore(SLV_STRING_GAMELOG)) {
StrMakeValidInPlace(SlGamelogRevision::revision_text, lastof(SlGamelogRevision::revision_text)); static_cast<LoggedChangeRevision *>(lc)->text = StrMakeValid(std::string_view(SlGamelogRevision::revision_text, lengthof(SlGamelogRevision::revision_text)));
static_cast<LoggedChangeRevision *>(lc)->text = SlGamelogRevision::revision_text;
} }
} }

View File

@ -573,8 +573,7 @@ bool ScriptInstance::IsPaused()
SlObject(nullptr, _script_byte); SlObject(nullptr, _script_byte);
static char buf[std::numeric_limits<decltype(_script_sl_byte)>::max()]; static char buf[std::numeric_limits<decltype(_script_sl_byte)>::max()];
SlCopy(buf, _script_sl_byte, SLE_CHAR); SlCopy(buf, _script_sl_byte, SLE_CHAR);
StrMakeValidInPlace(buf, buf + _script_sl_byte); if (data != nullptr) data->push_back(StrMakeValid(std::string_view(buf, _script_sl_byte)));
if (data != nullptr) data->push_back(std::string(buf));
return true; return true;
} }