From 4357809ce8238cfd0bc5d8c92b6da28068607d55 Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Wed, 26 Jul 2017 16:05:50 -0500 Subject: SCI32: Fix truncated save game names in Phant2 Phant2 creates save game names that append "" at the end of the game name, with an assumption that the game name is always exactly 36 characters long. This seems to be OK with other games too (tested GK1, SQ6, and Torin). --- engines/sci/engine/file.cpp | 4 +++- engines/sci/engine/file.h | 2 +- engines/sci/engine/kfile.cpp | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'engines/sci') diff --git a/engines/sci/engine/file.cpp b/engines/sci/engine/file.cpp index 2128433b90..7e218bc81c 100644 --- a/engines/sci/engine/file.cpp +++ b/engines/sci/engine/file.cpp @@ -371,7 +371,9 @@ bool fillSavegameDesc(const Common::String &filename, SavegameDesc *desc) { if (meta.name.lastChar() == '\n') meta.name.deleteLastChar(); - Common::strlcpy(desc->name, meta.name.c_str(), SCI_MAX_SAVENAME_LENGTH); + // At least Phant2 requires use of strncpy, since it creates save game + // names of exactly SCI_MAX_SAVENAME_LENGTH + strncpy(desc->name, meta.name.c_str(), SCI_MAX_SAVENAME_LENGTH); return desc; } diff --git a/engines/sci/engine/file.h b/engines/sci/engine/file.h index fee628aad5..1657dd3c7c 100644 --- a/engines/sci/engine/file.h +++ b/engines/sci/engine/file.h @@ -35,7 +35,7 @@ enum kFileOpenMode { }; enum { - SCI_MAX_SAVENAME_LENGTH = 36, ///< Maximum length of a savegame name (including terminator character). + SCI_MAX_SAVENAME_LENGTH = 36, ///< Maximum length of a savegame name (including optional terminator character). MAX_SAVEGAME_NR = 20 ///< Maximum number of savegames }; diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp index 1a6695f882..eb6cacbe19 100644 --- a/engines/sci/engine/kfile.cpp +++ b/engines/sci/engine/kfile.cpp @@ -426,7 +426,7 @@ reg_t kFileIOOpen(EngineState *s, int argc, reg_t *argv) { byte *out = buffer; for (uint i = 0; i < numSaves; ++i) { WRITE_UINT16(out, saves[i].id - kSaveIdShift); - Common::strlcpy((char *)out + sizeof(int16), saves[i].name, SCI_MAX_SAVENAME_LENGTH); + strncpy((char *)out + sizeof(int16), saves[i].name, SCI_MAX_SAVENAME_LENGTH); out += recordSize; } WRITE_UINT16(out, 0xFFFF); @@ -1372,7 +1372,9 @@ reg_t kGetSaveFiles32(EngineState *s, int argc, reg_t *argv) { for (uint i = 0; i < saves.size(); ++i) { const SavegameDesc &save = saves[i]; char *target = &descriptions.charAt(SCI_MAX_SAVENAME_LENGTH * i); - Common::strlcpy(target, save.name, SCI_MAX_SAVENAME_LENGTH); + // At least Phant2 requires use of strncpy, since it creates save game + // names of exactly SCI_MAX_SAVENAME_LENGTH + strncpy(target, save.name, SCI_MAX_SAVENAME_LENGTH); saveIds.setFromInt16(i, save.id - kSaveIdShift); } -- cgit v1.2.3