diff options
-rw-r--r-- | engines/sci/detection.cpp | 13 | ||||
-rw-r--r-- | engines/sci/engine/game.cpp | 5 | ||||
-rw-r--r-- | engines/sci/engine/vm.h | 2 |
3 files changed, 12 insertions, 8 deletions
diff --git a/engines/sci/detection.cpp b/engines/sci/detection.cpp index d44835c8c4..62099c1b6b 100644 --- a/engines/sci/detection.cpp +++ b/engines/sci/detection.cpp @@ -121,7 +121,7 @@ static const PlainGameDescriptor SciGameTitles[] = { /** * The fallback game descriptor used by the SCI engine's fallbackDetector. - * Contents of this struct are to be overwritten by the fallbackDetector. + * Contents of this struct are overwritten by the fallbackDetector. */ static ADGameDescription s_fallbackDesc = { "", @@ -133,6 +133,8 @@ static ADGameDescription s_fallbackDesc = { Common::GUIO_NONE }; +static char s_fallbackGameIdBuf[256]; + static const ADParams detectionParams = { // Pointer to ADGameDescription or its superset structure @@ -314,9 +316,12 @@ const ADGameDescription *SciMetaEngine::fallbackDetect(const Common::FSList &fsl return 0; } reg_t game_obj = segMan->lookupScriptExport(0, 0); - const char *gameId = segMan->getObjectName(game_obj); - debug(2, "Detected ID: \"%s\" at %04x:%04x", gameId, PRINT_REG(game_obj)); - s_fallbackDesc.gameid = convertSierraGameId(gameId, &s_fallbackDesc.flags, resMan); + const char *sierraGameId = segMan->getObjectName(game_obj); + debug(2, "Detected ID: \"%s\" at %04x:%04x", sierraGameId, PRINT_REG(game_obj)); + Common::String gameId = convertSierraGameId(sierraGameId, &s_fallbackDesc.flags, resMan); + strncpy(s_fallbackGameIdBuf, gameId.c_str(), sizeof(s_fallbackGameIdBuf) - 1); + s_fallbackGameIdBuf[sizeof(s_fallbackGameIdBuf) - 1] = 0; // Make sure string is NULL terminated + s_fallbackDesc.gameid = s_fallbackGameIdBuf; delete segMan; // Try to determine the game language diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index b48ec13448..f92c67505c 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -109,7 +109,7 @@ static const OldNewIdTableEntry s_oldNewTable[] = { { "", "", SCI_VERSION_NONE } }; -const char *convertSierraGameId(const char *gameId, uint32 *gameFlags, ResourceManager *resMan) { +Common::String convertSierraGameId(const char *gameId, uint32 *gameFlags, ResourceManager *resMan) { // Convert the id to lower case, so that we match all upper/lower case variants. Common::String sierraId = gameId; sierraId.toLowercase(); @@ -174,8 +174,7 @@ const char *convertSierraGameId(const char *gameId, uint32 *gameFlags, ResourceM return "qfg3"; } - // FIXME: Evil use of strdup here (we are leaking that memory, too) - return strdup(sierraId.c_str()); + return sierraId; } #ifdef USE_OLD_MUSIC_FUNCTIONS diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index da17119507..bc99f529aa 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -432,7 +432,7 @@ void script_uninstantiate(SegManager *segMan, int script_nr); * @param[in] gameFlags The game's flags, which are adjusted accordingly for demos * @return The equivalent ScummVM game id */ -const char *convertSierraGameId(const char *gameId, uint32 *gameFlags, ResourceManager *resMan); +Common::String convertSierraGameId(const char *gameId, uint32 *gameFlags, ResourceManager *resMan); /** * Initializes an SCI game |