Changeset - r27704:082d9bc39af4
[Not reviewed]
master
0 3 0
Rubidium - 14 months ago 2023-07-05 17:36:35
rubidium@openttd.org
Codechange: do not make a string valid in place, to then copy it
3 files changed with 5 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -2651,12 +2651,9 @@ static ChangeInfoResult LoadTranslationT
 
 */
 
static std::string ReadDWordAsString(ByteReader *reader)
 
{
 
	char output[5];
 
	for (int i = 0; i < 4; i++) output[i] = reader->ReadByte();
 
	output[4] = '\0';
 
	StrMakeValidInPlace(output, lastof(output));
 

	
 
	return std::string(output);
 
	std::string output;
 
	for (int i = 0; i < 4; i++) output.push_back(reader->ReadByte());
 
	return StrMakeValid(output);
 
}
 

	
 
/**
src/saveload/gamelog_sl.cpp
Show inline comments
 
@@ -68,8 +68,7 @@ public:
 
		SlObject(lc, this->GetLoadDescription());
 

	
 
		if (IsSavegameVersionBefore(SLV_STRING_GAMELOG)) {
 
			StrMakeValidInPlace(SlGamelogRevision::revision_text, lastof(SlGamelogRevision::revision_text));
 
			static_cast<LoggedChangeRevision *>(lc)->text = SlGamelogRevision::revision_text;
 
			static_cast<LoggedChangeRevision *>(lc)->text = StrMakeValid(std::string_view(SlGamelogRevision::revision_text, lengthof(SlGamelogRevision::revision_text)));
 
		}
 
	}
 

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

	
0 comments (0 inline, 0 general)