Skip to content

Commit b58c26a

Browse files
committed
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
1 parent 38e1eae commit b58c26a

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

artifacts/scripting/headers/define_extra.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@
475475
#define OBJ_DATA_DAMAGE_FLAGS (0x44)
476476
#define OBJ_DATA_DAMAGE_LAST_TURN (0x48)
477477
#define OBJ_DATA_WHO_HIT_ME (0x54) // current target of the critter
478+
#define OBJ_DATA_CRITTER_HP (0x58)
478479

479480
// compute attack result data offsets
480481
#define C_ATTACK_SOURCE (0x00)

sfall/FalloutEngine/Functions_def.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ WRAP_WATCOM_FUNC2(fo::DbFile*, db_fopen, const char*, path, const char*, mode)
307307
WRAP_WATCOM_FUNC3(char*, db_fgets, char*, buf, long, max_count, fo::DbFile*, file)
308308
WRAP_WATCOM_FFUNC4(long, db_fread, void*, buf, long, elsize, long, count, fo::DbFile*, file)
309309
WRAP_WATCOM_FFUNC3(long, db_fseek, fo::DbFile*, file, long, pos, long, origin)
310-
WRAP_WATCOM_FUNC2(void, db_free_file_list, char***, fileList, DWORD, arg2) // Destroys filelist array created by db_get_file_list
310+
WRAP_WATCOM_FUNC2(void, db_free_file_list, char const***, fileList, DWORD, arg2) // Destroys filelist array created by db_get_file_list
311311
WRAP_WATCOM_FUNC2(long, db_freadByte, fo::DbFile*, file, BYTE*, _out)
312312
WRAP_WATCOM_FUNC2(long, db_freadShort, fo::DbFile*, file, WORD*, _out)
313313
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
322322
WRAP_WATCOM_FUNC2(long, db_dir_entry, const char*, fileName, DWORD*, sizeOut) // Check fallout file and get file size (result 0 - file exists)
323323
// Searches files in DB by given path/filename mask and stores result in fileList
324324
// fileList is a pointer to a variable, that will be assigned with an address of an array of char* strings
325-
WRAP_WATCOM_FUNC2(long, db_get_file_list, const char*, searchMask, char***, fileList) // Returns number of elements in *fileList
325+
WRAP_WATCOM_FUNC2(long, db_get_file_list, const char*, searchMask, char const***, fileList) // Returns number of elements in *fileList
326326
WRAP_WATCOM_FUNC1(void*, dbase_open, const char*, fileName)
327327
WRAP_WATCOM_FUNC1(void, dbase_close, void*, dbPtr)
328328

sfall/Modules/ScriptExtender.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,16 @@ static void InitGlobalScripts() {
538538

539539
static void PrepareGlobalScriptsListByMask() {
540540
globalScriptFilesList.clear();
541-
for (auto& fileMask : globalScriptPathList) {
542-
char** filenames;
541+
bool hereBefore = false;
542+
for (const std::string fileMask : globalScriptPathList) {
543+
char const** filenames;
544+
auto w = filenames[1];
543545
auto basePath = fileMask.substr(0, fileMask.find_last_of("\\/") + 1); // path to scripts without mask
544546
int count = fo::func::db_get_file_list(fileMask.c_str(), &filenames);
545547

546548
for (int i = 0; i < count; i++) {
547-
char* name = _strlwr(filenames[i]); // name of the script in lower case
549+
std::string name(filenames[i]);
550+
ToLowerCase(name);
548551
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)
549552

550553
std::string baseName(name);
@@ -553,7 +556,7 @@ static void PrepareGlobalScriptsListByMask() {
553556

554557
baseName = baseName.substr(0, lastDot); // script name without extension
555558
if (basePath != fo::var::script_path_base || !IsGameScript(baseName.c_str())) {
556-
dlog_f("Found global script: %s\n", DL_SCRIPT, name);
559+
dlog_f("Found global script: %s\n", DL_SCRIPT, name.c_str());
557560
std::string fullPath(basePath);
558561
fullPath += name;
559562
// prevent loading global scripts with the same name from different directories

0 commit comments

Comments
 (0)