diff options
author | D G Turner | 2019-09-15 18:15:19 +0100 |
---|---|---|
committer | D G Turner | 2019-09-15 18:15:19 +0100 |
commit | 28fe02eb305d3de8e3e2da5791b0f7c74d68c255 (patch) | |
tree | 2d6b5dc929b3bb0d4faec67fd4ced43bdae2324a /engines/toon | |
parent | 04242ce829bd55f03e084b85a23055b23e598fb6 (diff) | |
download | scummvm-rg350-28fe02eb305d3de8e3e2da5791b0f7c74d68c255.tar.gz scummvm-rg350-28fe02eb305d3de8e3e2da5791b0f7c74d68c255.tar.bz2 scummvm-rg350-28fe02eb305d3de8e3e2da5791b0f7c74d68c255.zip |
TOON: Replace Various String Functions with Common String Usage
This removes the dependency on the unsafe strcpy and strcat string
functions with usage of Common::String instead.
Diffstat (limited to 'engines/toon')
-rw-r--r-- | engines/toon/anim.cpp | 10 | ||||
-rw-r--r-- | engines/toon/character.cpp | 12 | ||||
-rw-r--r-- | engines/toon/resource.cpp | 2 | ||||
-rw-r--r-- | engines/toon/script_func.cpp | 11 |
4 files changed, 16 insertions, 19 deletions
diff --git a/engines/toon/anim.cpp b/engines/toon/anim.cpp index c0f0638740..4cb7d6fb47 100644 --- a/engines/toon/anim.cpp +++ b/engines/toon/anim.cpp @@ -37,11 +37,11 @@ bool Animation::loadAnimation(const Common::String &file) { if (!fileData) return false; - strcpy(_name, "not_loaded"); - if (strncmp((char *)fileData, "KevinAguilar", 12)) + Common::strlcpy(_name, "not_loaded", sizeof(_name)); + if (!Common::String((char *)fileData, 12).equals("KevinAguilar")) return false; - Common::strlcpy(_name, file.c_str(), 32); + Common::strlcpy(_name, file.c_str(), sizeof(_name)); uint32 headerSize = READ_LE_UINT32(fileData + 16); uint32 uncompressedBytes = READ_LE_UINT32(fileData + 20); @@ -245,9 +245,7 @@ void Animation::drawFrameWithMaskAndScale(Graphics::Surface &surface, int32 fram uint8 *curRow = (uint8 *)surface.getPixels(); uint8 *curRowMask = mask->getDataPtr(); - bool shadowFlag = false; - if (strstr(_name, "SHADOW")) - shadowFlag = true; + bool shadowFlag = Common::String(_name).contains("SHADOW"); for (int16 y = yy1; y < yy2; y++) { for (int16 x = xx1; x < xx2; x++) { diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp index 3d7beeeafe..84b67cc52e 100644 --- a/engines/toon/character.cpp +++ b/engines/toon/character.cpp @@ -1020,8 +1020,7 @@ void Character::playAnim(int32 animId, int32 unused, int32 flags) { // get the anim to load const SpecialCharacterAnimation *anim = getSpecialAnimation(_id, animId); - char animName[20]; - strcpy(animName, anim->_filename); + Common::String animNameStr = anim->_filename; int32 facing = _facing; if (_id == 1) { @@ -1029,9 +1028,8 @@ void Character::playAnim(int32 animId, int32 unused, int32 flags) { facing = CharacterFlux::fixFacingForAnimation(facing, animId); } - if (strchr(animName, '?')) - *strchr(animName, '?') = '0' + facing; - strcat(animName, ".CAF"); + Common::replace(animNameStr, Common::String('?'), Common::String('0' + facing)); + animNameStr += ".CAF"; if (_animScriptId != -1 && (flags & 8) == 0) _vm->getSceneAnimationScript(_animScriptId)->_frozenForConversation = true; @@ -1046,7 +1044,7 @@ void Character::playAnim(int32 animId, int32 unused, int32 flags) { _flags |= 1; // old special anim was talking anim ? in this case we don't wait for the character to be ready - bool wasTalkAnim = _specialAnim && strstr(_specialAnim->_name, "TLK"); + bool wasTalkAnim = _specialAnim && Common::String(_specialAnim->_name).contains("TLK"); // wait for the character to be ready while (_animScriptId != -1 && _animationInstance && _animationInstance->getFrame() > 0 && !wasTalkAnim && (_specialAnim && _animationInstance->getAnimation() != _specialAnim)) { @@ -1061,7 +1059,7 @@ void Character::playAnim(int32 animId, int32 unused, int32 flags) { delete _specialAnim; _specialAnim = new Animation(_vm); - _specialAnim->loadAnimation(animName); + _specialAnim->loadAnimation(animNameStr.c_str()); _animSpecialId = animId; diff --git a/engines/toon/resource.cpp b/engines/toon/resource.cpp index f7c02d5f10..3dbb6557fd 100644 --- a/engines/toon/resource.cpp +++ b/engines/toon/resource.cpp @@ -273,7 +273,7 @@ void PakFile::open(Common::SeekableReadStream *rs, const Common::String &packNam currentPos += 4 + nameSize; PakFile::File newFile; - strcpy(newFile._name, name); + Common::strlcpy(newFile._name, name, sizeof(newFile._name)); newFile._offset = offset; newFile._size = nextOffset - offset; _numFiles++; diff --git a/engines/toon/script_func.cpp b/engines/toon/script_func.cpp index d2a9de3c02..761852b66f 100644 --- a/engines/toon/script_func.cpp +++ b/engines/toon/script_func.cpp @@ -311,14 +311,15 @@ int32 ScriptFunc::sys_Cmd_Flip_Screens(EMCState *state) { } int32 ScriptFunc::sys_Cmd_Play_Flic(EMCState *state) { - + Common::String stateText = GetText(0, state); Common::String name; // workaround for the video of the beginning - if (strstr(GetText(0, state), "209")) - name = GetText(0, state); - else - name = _vm->createRoomFilename(GetText(0, state)); + if (stateText.contains("209")) { + name = stateText; + } else { + name = _vm->createRoomFilename(stateText.c_str()); + } int32 stopMusic = stackPos(2); _vm->getMoviePlayer()->play(name, stopMusic); |