From 0069fb107267705b186fbed098a62a78624855ae Mon Sep 17 00:00:00 2001 From: Matt Hargett Date: Sat, 7 Sep 2002 19:55:16 +0000 Subject: Fix heap corruption. Fix compiler warning. svn-id: r4901 --- common/gameDetector.cpp | 6 ++++-- common/scummsys.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/gameDetector.cpp b/common/gameDetector.cpp index 237dbf663f..94e46da0dc 100644 --- a/common/gameDetector.cpp +++ b/common/gameDetector.cpp @@ -548,8 +548,10 @@ int GameDetector::detectMain(int argc, char **argv) && _gameDataPath[strlen(_gameDataPath)-1] != '\\') { char slashless[1024]; /* Append slash to path */ strcpy(slashless, _gameDataPath); - _gameDataPath = (char *)malloc((strlen(slashless) + 1) * sizeof(char)); - sprintf(_gameDataPath, "%s/", slashless); + + // need to allocate 2 extra bytes, one for the "/" and one for the NULL terminator + _gameDataPath = (char *)malloc((strlen(slashless) + 2) * sizeof(char)); + snprintf(_gameDataPath, strlen(_gameDataPath), "%s/", slashless); } if (_amiga) diff --git a/common/scummsys.h b/common/scummsys.h index 5234c1ceaf..9048a1e3d2 100644 --- a/common/scummsys.h +++ b/common/scummsys.h @@ -34,6 +34,7 @@ const bool true(1), false(0); //#pragma warning (disable: 4101) #define scumm_stricmp stricmp +#define snprintf _snprintf #if defined(CHECK_HEAP) #undef CHECK_HEAP -- cgit v1.2.3