From 85556572078c7a725dd376217f4572c13188d6c1 Mon Sep 17 00:00:00 2001 From: D G Turner Date: Sat, 14 Sep 2019 03:03:17 +0100 Subject: HDB: Improve String Code Usage in HDB Engine Code --- engines/hdb/hdb.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'engines') diff --git a/engines/hdb/hdb.cpp b/engines/hdb/hdb.cpp index 8788c2037f..0de3f32eda 100644 --- a/engines/hdb/hdb.cpp +++ b/engines/hdb/hdb.cpp @@ -323,15 +323,15 @@ bool HDBGame::restartMap() { bool HDBGame::startMap(const char *name) { // save last mapname - strcpy(_lastMapname, _currentMapname); + Common::strlcpy(_lastMapname, _currentMapname, sizeof(_lastMapname)); // set current mapname - strcpy(_currentMapname, name); - strcat(_currentMapname, ".MSM"); + Common::strlcpy(_currentMapname, name, sizeof(_currentMapname)); + Common::strlcat(_currentMapname, ".MSM", sizeof(_currentMapname)); // set current luaname - strcpy(_currentLuaName, name ); - strcat(_currentLuaName, ".LUA"); + Common::strlcpy(_currentLuaName, name, sizeof(_currentLuaName)); + Common::strlcat(_currentLuaName, ".LUA", sizeof(_currentLuaName)); restartMap(); @@ -932,25 +932,26 @@ Common::Error HDBGame::run() { #endif if (ConfMan.hasKey("boot_param")) { - char mapname[20]; int arg = ConfMan.getInt("boot_param"); int actionMode = MIN(arg / 100, 1); int level = MIN(arg % 100, 31); setActionMode(actionMode); - if (level <= 30) - snprintf(mapname, 10, "MAP%02d", level); - else - strcpy(mapname, "CINE_OUTRO"); + Common::String mapNameString = Common::String::format("MAP%02d", level); + + if (level > 30) { + mapNameString = "CINE_OUTRO"; + } - if (isDemo()) - strcat(mapname, "_DEMO"); + if (isDemo()) { + mapNameString += "_DEMO"; + } - debug("Starting level %s in %s", mapname, getActionMode() ? "Action Mode" : "Puzzle Mode"); + debug("Starting level %s in %s Mode", mapNameString.c_str(), getActionMode() ? "Action" : "Puzzle"); _ai->clearPersistent(); - startMap(mapname); + startMap(mapNameString.c_str()); _gameState = GAME_PLAY; } else { -- cgit v1.2.3