From 28fe02eb305d3de8e3e2da5791b0f7c74d68c255 Mon Sep 17 00:00:00 2001 From: D G Turner Date: Sun, 15 Sep 2019 18:15:19 +0100 Subject: 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. --- engines/toon/anim.cpp | 10 ++++------ engines/toon/character.cpp | 12 +++++------- engines/toon/resource.cpp | 2 +- engines/toon/script_func.cpp | 11 ++++++----- 4 files changed, 16 insertions(+), 19 deletions(-) (limited to 'engines/toon') 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); -- cgit v1.2.3