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
 
@@ -2648,18 +2648,15 @@ static ChangeInfoResult LoadTranslationT
 
 * and to return it as a valid string.
 
 * @param reader The source of the DWord.
 
 * @return The read DWord as string.
 
 */
 
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);
 
}
 

	
 
/**
 
 * Define properties for global variables
 
 * @param gvid ID of the global variable.
 
 * @param numinfo Number of subsequent IDs to change the property for.
src/saveload/gamelog_sl.cpp
Show inline comments
 
@@ -65,14 +65,13 @@ public:
 
	void Load(LoggedChange *lc) const override
 
	{
 
		if (lc->ct != GLCT_REVISION) return;
 
		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)));
 
		}
 
	}
 

	
 
	void LoadCheck(LoggedChange *lc) const override { this->Load(lc); }
 
};
 

	
src/script/script_instance.cpp
Show inline comments
 
@@ -570,14 +570,13 @@ bool ScriptInstance::IsPaused()
 
		}
 

	
 
		case SQSL_STRING: {
 
			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;
 
		}
 

	
 
		case SQSL_ARRAY:
 
		case SQSL_TABLE: {
 
			if (data != nullptr) data->push_back((SQSaveLoadType)_script_sl_byte);
0 comments (0 inline, 0 general)