diff --git a/src/game/combatai.cc b/src/game/combatai.cc index 0428024..1a56261 100644 --- a/src/game/combatai.cc +++ b/src/game/combatai.cc @@ -592,7 +592,7 @@ static int ai_find_attackers(Object* critter, Object** a2, Object** a3, Object** Object* ai_danger_source(Object* critter) { Object* who_hit_me; - Object* targets[4]; + Object* targets[4] = {}; int index; who_hit_me = critter->data.critter.combat.whoHitMe; diff --git a/src/game/game.cc b/src/game/game.cc index c01b514..aaffc58 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -974,7 +974,7 @@ int game_load_info_vars(const char* path, const char* section, int* variablesLis } while (db_fgets(string, 258, stream)) { - if (string[0] == '\n') { + if (string[0] == '\n' || string[0] == '\r') { continue; } diff --git a/src/game/gsound.cc b/src/game/gsound.cc index e0bf1e2..93fc7d3 100644 --- a/src/game/gsound.cc +++ b/src/game/gsound.cc @@ -636,7 +636,9 @@ int gsound_background_play(const char* fileName, int a2, int a3, int a4) background_storage_requested = a3; background_loop_requested = a4; - strcpy(background_fname_requested, fileName); + if (background_fname_requested != fileName) { + strcpy(background_fname_requested, fileName); + } if (!gsound_initialized) { return -1; diff --git a/src/game/main.cc b/src/game/main.cc index 4f8efc1..e0e9939 100644 --- a/src/game/main.cc +++ b/src/game/main.cc @@ -88,6 +88,10 @@ static bool main_death_voiceover_done; // 0x4725E8 int gnw_main(int argc, char** argv) { +#ifndef NDEBUG + debug_register_env(); +#endif + if (!autorun_mutex_create()) { return 1; } diff --git a/src/game/map.cc b/src/game/map.cc index 737c258..e84b398 100644 --- a/src/game/map.cc +++ b/src/game/map.cc @@ -1007,6 +1007,7 @@ int map_load_file(DB_FILE* stream) strcat(path, ".GAM"); game_load_info_vars(path, "MAP_GLOBAL_VARS:", &num_map_global_vars, &map_global_vars); + map_global_pointers.resize(num_map_global_vars); map_data.globalVariablesCount = num_map_global_vars; } diff --git a/src/game/proto.cc b/src/game/proto.cc index f360133..305b9ff 100644 --- a/src/game/proto.cc +++ b/src/game/proto.cc @@ -2,6 +2,7 @@ #include #include +#include #include "game/art.h" #include "game/combat.h" @@ -221,14 +222,11 @@ int proto_list_str(int pid, char* proto_path) return -1; } - char* pch = strchr(string, ' '); - if (pch != NULL) { - *pch = '\0'; - } - - pch = strchr(string, '\n'); - if (pch != NULL) { - *pch = '\0'; + for (auto pch = string; *pch; pch++) { + if (isspace(*pch)) { + *pch = '\0'; + break; + } } strcpy(proto_path, string); diff --git a/src/int/support/intextra.cc b/src/int/support/intextra.cc index 60bb6ba..a0b0e79 100644 --- a/src/int/support/intextra.cc +++ b/src/int/support/intextra.cc @@ -1437,7 +1437,7 @@ static void op_obj_can_see_obj(Program* program) stat_level(object1, STAT_PERCEPTION); if (is_within_perception(object1, object2)) { - Object* a5; + Object* a5 = nullptr; make_straight_path(object1, object1->tile, object2->tile, NULL, &a5, 16); if (a5 == object2) { result = 1; diff --git a/src/platform_compat.cc b/src/platform_compat.cc index 972593b..b8ea2c4 100644 --- a/src/platform_compat.cc +++ b/src/platform_compat.cc @@ -310,14 +310,18 @@ void compat_resolve_path(char* path) bool found = false; - struct dirent* entry = readdir(dir); - while (entry != NULL) { - if (strlen(entry->d_name) == length && compat_strnicmp(pch, entry->d_name, length) == 0) { - strncpy(pch, entry->d_name, length); - found = true; - break; + if (length) { + struct dirent* entry = readdir(dir); + while (entry != NULL) { + if (strlen(entry->d_name) == length && compat_strnicmp(pch, entry->d_name, length) == 0) { + strncpy(pch, entry->d_name, length); + found = true; + break; + } + entry = readdir(dir); } - entry = readdir(dir); + } else { + found = true; } closedir(dir); diff --git a/src/plib/color/color.cc b/src/plib/color/color.cc index 08c10c0..a51f781 100644 --- a/src/plib/color/color.cc +++ b/src/plib/color/color.cc @@ -477,7 +477,7 @@ bool loadColorTable(const char* path) // NOTE: Uninline. colorRead(handle, colorTable, 0x8000); - unsigned int type; + unsigned int type = 0; // NOTE: Uninline. colorRead(handle, &type, sizeof(type)); diff --git a/src/plib/gnw/debug.cc b/src/plib/gnw/debug.cc index ea73b33..986cd14 100644 --- a/src/plib/gnw/debug.cc +++ b/src/plib/gnw/debug.cc @@ -55,7 +55,7 @@ void debug_register_mono() // 0x4B2DD8 void debug_register_log(const char* fileName, const char* mode) { - if ((mode[0] == 'w' && mode[1] == 'a') && mode[1] == 't') { + if ((mode[0] == 'w' || mode[0] == 'a') && mode[1] == 't') { if (fd != NULL) { fclose(fd); } @@ -139,7 +139,12 @@ int debug_printf(const char* format, ...) if (debug_func != NULL) { char string[260]; - vsnprintf(string, sizeof(string), format, args); + vsnprintf(string, sizeof(string) - 1, format, args); + const auto len = strlen(string); + if (len && string[len - 1] >= ' ') { + string[len] = '\n'; + string[len + 1] = '\0'; + } rc = debug_func(string); } else {