shithub: cstory

Download patch

ref: 7a84cdf9b107510f765bcc8dee496b9ba800b8fe
parent: b0612e5369801cbe8e1fa7f2d2dd69b2ba736170
author: Jacob Moody <moody@posixcafe.org>
date: Mon Dec 18 23:08:57 EST 2023

refactor global text script stashed path to be more C friendly

This was a bug from the big std::string conversion. This
field stashes the loaded path of the script for when we have
two scripts firing together. Instead of saving a pointer, just
write it to a buffer.

--- a/src/ArmsItem.cpp
+++ b/src/ArmsItem.cpp
@@ -421,12 +421,12 @@
 
 int CampLoop(void)
 {
-	char *old_script_path;
+	char old_script_path[128];
 
 	RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
 
 	// Save the current script path (to restore it when we get out of the inventory)
-	old_script_path = GetTextScriptPath();
+	GetTextScriptPath(old_script_path, sizeof old_script_path);
 
 	// Load the inventory script
 	LoadTextScript2("ArmsItem.tsc");
--- a/src/SelStage.cpp
+++ b/src/SelStage.cpp
@@ -166,13 +166,13 @@
 
 int StageSelectLoop(int *p_event)
 {
-	char *old_script_path;
+	char old_script_path[128];
 
 	RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
 
 	gSelectedStage = 0;
 	BackupSurface(SURFACE_ID_SCREEN_GRAB, &grcFull);
-	old_script_path = GetTextScriptPath();
+	GetTextScriptPath(old_script_path, sizeof old_script_path);
 	LoadTextScript2("StageSelect.tsc");
 	gStageSelectTitleY = (WINDOW_HEIGHT / 2) - 66;
 	StartTextScript(gPermitStage[gSelectedStage].index + 1000);
--- a/src/TextScr.cpp
+++ b/src/TextScr.cpp
@@ -152,7 +152,7 @@
 	fclose(fp);
 
 	// Set path
-	gTS.path = name;
+	snprint(gTS.path, sizeof gTS.path, "%s", name);
 
 	// Decrypt data
 	EncryptionBinaryData2((unsigned char*)gTS.data, gTS.size);
@@ -217,15 +217,15 @@
 
 	// Set parameters
 	gTS.size = head_size + body_size;
-	gTS.path = name;
+	snprint(gTS.path, sizeof gTS.path, "%s", name);
 
 	return TRUE;
 }
 
 // Get current path
-char *GetTextScriptPath(void)
+void GetTextScriptPath(char *s, int n)
 {
-	return gTS.path;
+	snprint(s, n, "%s", gTS.path);
 }
 
 // Get 4 digit number from TSC data
--- a/src/TextScr.h
+++ b/src/TextScr.h
@@ -12,7 +12,7 @@
 typedef struct TEXT_SCRIPT
 {
 	// Path (reload when exit teleporter menu/inventory)
-	char *path;
+	char path[128];
 
 	// Script buffer
 	long size;
@@ -69,7 +69,7 @@
 void EncryptionBinaryData2(unsigned char *pData, long size);
 BOOL LoadTextScript2(const char *name);
 BOOL LoadTextScript_Stage(const char *name);
-char* GetTextScriptPath(void);
+void GetTextScriptPath(char*, int);
 BOOL StartTextScript(int no);
 void StopTextScript(void);
 void PutTextScript(void);