Page MenuHomeFeedback Tracker

string corruption when using string.Replace function
Assigned, UrgentPublic

Description

When I tried to make some code, which read my clipboard contents containing some Json Data and trying to replace some fields before parsing the data, I noticed it would get cut off and corrupted after the string.Replace call replaced 0 instances of the string

Details

Severity
Crash
Resolution
Open
Reproducibility
Always
Operating System
Windows 11 x64
Category
General
Steps To Reproduce
modded class MissionGameplay {

	void MissionGameplay() {
		CreateCorruptedString();
	}

	void CreateCorruptedString() {
		string str;
		GetGame().CopyFromClipboard(str);
		Print("Original Length: " + str.Length());
		FileHandle handle = OpenFile("$profile:original.txt", FileMode.WRITE);
		FPrint(handle, str);
		CloseFile(handle);
		int rep1 = str.Replace("\"param7\":{},", "");
		Print("Replaced First: " + rep1 + " Length: " + str.Length());
		int rep2 = str.Replace("\"param7\": {},", "");
		Print("Replaced Second: " + rep2 + " Length: " + str.Length());
		int rep3 = str.Replace("test", "text");
		Print("Replaced Thrid: " + rep3 + " Length: " + str.Length());
		handle = OpenFile("$profile:modified.txt", FileMode.WRITE);
		FPrint(handle, str);
		CloseFile(handle);
	}
}

my output was:

SCRIPT       : Original Length: 4024
SCRIPT       : Replaced First: 0 Length: 1096
SCRIPT       : Replaced Second: 0 Length: 1096
SCRIPT       : Replaced Thrid: 0 Length: 1096

Event Timeline

LBmaster created this task.Feb 18 2024, 5:46 PM
LBmaster added a comment.EditedFeb 18 2024, 5:52 PM

It not only happens when I get the string in there with the CopyFromClipboard, but also when doing something like string str = "..." and put all the data with escaped quotes in there.

It doesn't even matter what the content of the string is. For example putting in 4000 time "a" and letting it run, still yields the same result

Geez changed the task status from New to Assigned.Feb 19 2024, 12:37 PM