[Scummvm-git-logs] scummvm master -> 84d0a294af531c770062f3e65ca9a1b5b1b17f02

digitall dgturner at iee.org
Sun Sep 15 21:23:25 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:
84d0a294af SCUMM: Replace Various String Functions with Common String Usage


Commit: 84d0a294af531c770062f3e65ca9a1b5b1b17f02
    https://github.com/scummvm/scummvm/commit/84d0a294af531c770062f3e65ca9a1b5b1b17f02
Author: D G Turner (digitall at scummvm.org)
Date: 2019-09-15T20:20:03+01:00

Commit Message:
SCUMM: 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/scumm/imuse/imuse.cpp
    engines/scumm/imuse/imuse_player.cpp
    engines/scumm/string.cpp


diff --git a/engines/scumm/imuse/imuse.cpp b/engines/scumm/imuse/imuse.cpp
index 50a1330..1d52539 100644
--- a/engines/scumm/imuse/imuse.cpp
+++ b/engines/scumm/imuse/imuse.cpp
@@ -1468,8 +1468,6 @@ void IMuseInternal::initMidiDriver(TimerCallbackInfo *info) {
 
 void IMuseInternal::initMT32(MidiDriver *midi) {
 	byte buffer[52];
-	char info[256] = "ScummVM ";
-	int len;
 
 	// Reset the MT-32
 	midi->sysEx((const byte *) "\x41\x10\x16\x12\x7f\x00\x00\x01\x00", 9);
@@ -1485,15 +1483,16 @@ void IMuseInternal::initMT32(MidiDriver *midi) {
 	_system->delayMillis(250);
 
 	// Compute version string (truncated to 20 chars max.)
-	strcat(info, gScummVMVersion);
-	len = strlen(info);
+	Common::String infoStr = "ScummVM ";
+	infoStr += gScummVMVersion;
+	int len = infoStr.size();
 	if (len > 20)
 		len = 20;
 
 	// Display a welcome message on MT-32 displays.
 	memcpy(&buffer[0], "\x41\x10\x16\x12\x20\x00\x00", 7);
 	memcpy(&buffer[7], "                    ", 20);
-	memcpy(buffer + 7 + (20 - len) / 2, info, len);
+	memcpy(buffer + 7 + (20 - len) / 2, infoStr.c_str(), len);
 	byte checksum = 0;
 	for (int i = 4; i < 27; ++i)
 		checksum -= buffer[i];
diff --git a/engines/scumm/imuse/imuse_player.cpp b/engines/scumm/imuse/imuse_player.cpp
index b251e15..5e5c6ae 100644
--- a/engines/scumm/imuse/imuse_player.cpp
+++ b/engines/scumm/imuse/imuse_player.cpp
@@ -408,12 +408,12 @@ void Player::sysEx(const byte *p, uint16 len) {
 
 	if (!_scanning) {
 		for (a = 0; a < len + 1 && a < 19; ++a) {
-			sprintf((char *)&buf[a * 3], " %02X", p[a]);
-		} // next for
+			snprintf((char *)&buf[a * 3], 3 * sizeof(char), " %02X", p[a]);
+		}
 		if (a < len + 1) {
 			buf[a * 3] = buf[a * 3 + 1] = buf[a * 3 + 2] = '.';
 			++a;
-		} // end if
+		}
 		buf[a * 3] = '\0';
 		debugC(DEBUG_IMUSE, "[%02d] SysEx:%s", _id, buf);
 	}
diff --git a/engines/scumm/string.cpp b/engines/scumm/string.cpp
index 9ea889c..a127de3 100644
--- a/engines/scumm/string.cpp
+++ b/engines/scumm/string.cpp
@@ -1481,16 +1481,15 @@ void ScummEngine_v7::playSpeech(const byte *ptr) {
 		return;
 
 	if ((_game.id == GID_DIG || _game.id == GID_CMI) && ptr[0]) {
-		char pointer[20];
-		strcpy(pointer, (const char *)ptr);
+		Common::String pointerStr((const char *)ptr);
 
 		// Play speech
 		if (!(_game.features & GF_DEMO) && (_game.id == GID_CMI)) // CMI demo does not have .IMX for voice
-			strcat(pointer, ".IMX");
+			pointerStr += ".IMX";
 
 		_sound->stopTalkSound();
 		_imuseDigital->stopSound(kTalkSoundID);
-		_imuseDigital->startVoice(kTalkSoundID, pointer);
+		_imuseDigital->startVoice(kTalkSoundID, pointerStr.c_str());
 		_sound->talkSound(0, 0, 2);
 	}
 }





More information about the Scummvm-git-logs mailing list