Replace some strncpy usages with Common::strlcpy.

svn-id: r49086
This commit is contained in:
Johannes Schickel 2010-05-18 18:16:47 +00:00
parent e4d1c8a1bd
commit 62717eafc4
3 changed files with 4 additions and 8 deletions

View File

@ -954,9 +954,7 @@ Common::Error TinselEngine::loadGameState(int slot) {
Common::Error TinselEngine::saveGameState(int slot, const char *desc) {
Common::String saveName = _vm->getSavegameFilename((int16)(slot + 1));
char saveDesc[SG_DESC_LEN];
strncpy(saveDesc, desc, SG_DESC_LEN);
// Make sure that saveDesc is 0-terminated
saveDesc[SG_DESC_LEN - 1] = '\0';
Common::strlcpy(saveDesc, desc, SG_DESC_LEN);
SaveGame((char *)saveName.c_str(), saveDesc);
ProcessSRQueue(); // This shouldn't be needed, but for some reason it is...
return Common::kNoError; // TODO: return success/failure

View File

@ -288,8 +288,7 @@ void LoadFile(MEMHANDLE *pH) {
}
// extract and zero terminate the filename
strncpy(szFilename, pH->szName, sizeof(pH->szName));
szFilename[sizeof(pH->szName)] = 0;
Common::strlcpy(szFilename, pH->szName, sizeof(pH->szName));
if (f.open(szFilename)) {
// read the data

View File

@ -365,9 +365,8 @@ int getList(Common::SaveFileManager *saveFileMan, const Common::String &target)
}
#endif
strncpy(savedFiles[i].name, fname.c_str(), FNAMELEN);
strncpy(savedFiles[i].desc, hdr.desc, SG_DESC_LEN);
savedFiles[i].desc[SG_DESC_LEN - 1] = 0;
Common::strlcpy(savedFiles[i].name, fname.c_str(), FNAMELEN);
Common::strlcpy(savedFiles[i].desc, hdr.desc, SG_DESC_LEN);
savedFiles[i].dateTime = hdr.dateTime;
++numSfiles;