diff options
author | Colin Snover | 2017-12-06 16:23:48 -0600 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-18 16:30:05 +0200 |
commit | 0851a30769c6307796d6866da073632c83d61185 (patch) | |
tree | 0d58a312ac337d5fbf5a70c51758ead2de7f8189 /engines/agi/objects.cpp | |
parent | 4db0f20f4797ae909edb785e9a8b03c095386feb (diff) | |
download | scummvm-rg350-0851a30769c6307796d6866da073632c83d61185.tar.gz scummvm-rg350-0851a30769c6307796d6866da073632c83d61185.tar.bz2 scummvm-rg350-0851a30769c6307796d6866da073632c83d61185.zip |
AGI: Replace use of strdup with Common::String
It was also necessary to make sure that the Common::String objects
were initialised correctly by switching to use a C++ container
for engine objects instead of calloc, since they were no longer
C-compatible PODs.
Diffstat (limited to 'engines/agi/objects.cpp')
-rw-r--r-- | engines/agi/objects.cpp | 32 |
1 files changed, 5 insertions, 27 deletions
diff --git a/engines/agi/objects.cpp b/engines/agi/objects.cpp index b6c628c32d..3a7bfc98f6 100644 --- a/engines/agi/objects.cpp +++ b/engines/agi/objects.cpp @@ -26,20 +26,12 @@ namespace Agi { -int AgiEngine::allocObjects(int n) { - if ((_objects = (AgiObject *)calloc(n, sizeof(struct AgiObject))) == NULL) - return errNotEnoughMemory; - - return errOK; -} - int AgiEngine::decodeObjects(uint8 *mem, uint32 flen) { unsigned int i, so, padsize, spos; padsize = _game.gameFlags & ID_AMIGA ? 4 : 3; _game.numObjects = 0; - _objects = NULL; // check if first pointer exceeds file size // if so, its encrypted, else it is not @@ -60,8 +52,7 @@ int AgiEngine::decodeObjects(uint8 *mem, uint32 flen) { _game.numObjects = READ_LE_UINT16(mem) / padsize; debugC(5, kDebugLevelResources, "num_objects = %d (padsize = %d)", _game.numObjects, padsize); - if (allocObjects(_game.numObjects) != errOK) - return errNotEnoughMemory; + _objects.resize(_game.numObjects); // build the object list spos = getVersion() >= 0x2000 ? padsize : 0; @@ -72,15 +63,15 @@ int AgiEngine::decodeObjects(uint8 *mem, uint32 flen) { offset = READ_LE_UINT16(mem + so) + spos; if ((uint) offset < flen) { - _objects[i].name = (char *)strdup((const char *)mem + offset); + _objects[i].name = (const char *)mem + offset; } else { warning("object %i name beyond object filesize (%04x > %04x)", i, offset, flen); - _objects[i].name = strdup(""); + _objects[i].name.clear(); } // Don't show the invalid "?" object in ego's inventory in the fanmade // game Beyond the Titanic 2 (bug #3116541). - if (!strcmp(_objects[i].name, "?") && _objects[i].location == EGO_OWNED) + if (_objects[i].name == "?" && _objects[i].location == EGO_OWNED) _objects[i].location = 0; } debug(0, "Reading objects: %d objects read.", _game.numObjects); @@ -131,19 +122,6 @@ int AgiEngine::readObjects(Common::File &fp, int flen) { return errOK; } -void AgiEngine::unloadObjects() { - unsigned int i; - - if (_objects != NULL) { - for (i = 0; i < _game.numObjects; i++) { - free(_objects[i].name); - _objects[i].name = NULL; - } - free(_objects); - _objects = NULL; - } -} - void AgiEngine::objectSetLocation(uint16 objectNr, int i) { if (objectNr >= _game.numObjects) { warning("AgiEngine::objectSetLocation: Can't access object %d.\n", objectNr); @@ -165,7 +143,7 @@ const char *AgiEngine::objectName(uint16 objectNr) { warning("AgiEngine::objectName: Can't access object %d.\n", objectNr); return ""; } - return _objects[objectNr].name; + return _objects[objectNr].name.c_str(); } } // End of namespace Agi |