[Scummvm-git-logs] scummvm master -> 28fe02eb305d3de8e3e2da5791b0f7c74d68c255

digitall dgturner at iee.org
Sun Sep 15 19:19:06 CEST 2019


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
28fe02eb30 TOON: Replace Various String Functions with Common String Usage


Commit: 28fe02eb305d3de8e3e2da5791b0f7c74d68c255
    https://github.com/scummvm/scummvm/commit/28fe02eb305d3de8e3e2da5791b0f7c74d68c255
Author: D G Turner (digitall at scummvm.org)
Date: 2019-09-15T18:15:19+01:00

Commit Message:
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.

Changed paths:
    engines/toon/anim.cpp
    engines/toon/character.cpp
    engines/toon/resource.cpp
    engines/toon/script_func.cpp


diff --git a/engines/toon/anim.cpp b/engines/toon/anim.cpp
index c0f0638..4cb7d6f 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 3d7beee..84b67cc 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 f7c02d5..3dbb655 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 d2a9de3..761852b 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);





More information about the Scummvm-git-logs mailing list