Fixed crash in PrepareGlobalScriptsListByMask in ReleaseXP build when using v141_xp toolset

- Passing a raw pointer to fileMask's char array to db_get_file_list seemed to be the main cause
- I've also replaced the use of _strlwr with ToLowerCase on the string copy, to avoiding editing strings returned from engine function in-place
- Clarified the constness of file list variable used by db_*_file_list for the same reason
This commit is contained in:
phobos2077
2026-02-28 15:54:28 +01:00
parent 38e1eaef64
commit b58c26a401
3 changed files with 10 additions and 6 deletions
@@ -475,6 +475,7 @@
#define OBJ_DATA_DAMAGE_FLAGS (0x44)
#define OBJ_DATA_DAMAGE_LAST_TURN (0x48)
#define OBJ_DATA_WHO_HIT_ME (0x54) // current target of the critter
#define OBJ_DATA_CRITTER_HP (0x58)
// compute attack result data offsets
#define C_ATTACK_SOURCE (0x00)
+2 -2
View File
@@ -307,7 +307,7 @@ WRAP_WATCOM_FUNC2(fo::DbFile*, db_fopen, const char*, path, const char*, mode)
WRAP_WATCOM_FUNC3(char*, db_fgets, char*, buf, long, max_count, fo::DbFile*, file)
WRAP_WATCOM_FFUNC4(long, db_fread, void*, buf, long, elsize, long, count, fo::DbFile*, file)
WRAP_WATCOM_FFUNC3(long, db_fseek, fo::DbFile*, file, long, pos, long, origin)
WRAP_WATCOM_FUNC2(void, db_free_file_list, char***, fileList, DWORD, arg2) // Destroys filelist array created by db_get_file_list
WRAP_WATCOM_FUNC2(void, db_free_file_list, char const***, fileList, DWORD, arg2) // Destroys filelist array created by db_get_file_list
WRAP_WATCOM_FUNC2(long, db_freadByte, fo::DbFile*, file, BYTE*, _out)
WRAP_WATCOM_FUNC2(long, db_freadShort, fo::DbFile*, file, WORD*, _out)
WRAP_WATCOM_FUNC2(long, db_freadInt, fo::DbFile*, file, DWORD*, _out)
@@ -322,7 +322,7 @@ WRAP_WATCOM_FFUNC3(long, db_fwriteByteCount, fo::DbFile*, file, const BYTE*, cpt
WRAP_WATCOM_FUNC2(long, db_dir_entry, const char*, fileName, DWORD*, sizeOut) // Check fallout file and get file size (result 0 - file exists)
// Searches files in DB by given path/filename mask and stores result in fileList
// fileList is a pointer to a variable, that will be assigned with an address of an array of char* strings
WRAP_WATCOM_FUNC2(long, db_get_file_list, const char*, searchMask, char***, fileList) // Returns number of elements in *fileList
WRAP_WATCOM_FUNC2(long, db_get_file_list, const char*, searchMask, char const***, fileList) // Returns number of elements in *fileList
WRAP_WATCOM_FUNC1(void*, dbase_open, const char*, fileName)
WRAP_WATCOM_FUNC1(void, dbase_close, void*, dbPtr)
+7 -4
View File
@@ -538,13 +538,16 @@ static void InitGlobalScripts() {
static void PrepareGlobalScriptsListByMask() {
globalScriptFilesList.clear();
for (auto& fileMask : globalScriptPathList) {
char** filenames;
bool hereBefore = false;
for (const std::string fileMask : globalScriptPathList) {
char const** filenames;
auto w = filenames[1];
auto basePath = fileMask.substr(0, fileMask.find_last_of("\\/") + 1); // path to scripts without mask
int count = fo::func::db_get_file_list(fileMask.c_str(), &filenames);
for (int i = 0; i < count; i++) {
char* name = _strlwr(filenames[i]); // name of the script in lower case
std::string name(filenames[i]);
ToLowerCase(name);
if (name[0] != 'g' || name[1] != 'l') continue; // fix bug in db_get_file_list fuction (if the script name begins with a non-Latin character)
std::string baseName(name);
@@ -553,7 +556,7 @@ static void PrepareGlobalScriptsListByMask() {
baseName = baseName.substr(0, lastDot); // script name without extension
if (basePath != fo::var::script_path_base || !IsGameScript(baseName.c_str())) {
dlog_f("Found global script: %s\n", DL_SCRIPT, name);
dlog_f("Found global script: %s\n", DL_SCRIPT, name.c_str());
std::string fullPath(basePath);
fullPath += name;
// prevent loading global scripts with the same name from different directories