From 84d0a294af531c770062f3e65ca9a1b5b1b17f02 Mon Sep 17 00:00:00 2001 From: D G Turner Date: Sun, 15 Sep 2019 20:20:03 +0100 Subject: 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. --- engines/scumm/imuse/imuse.cpp | 9 ++++----- engines/scumm/imuse/imuse_player.cpp | 6 +++--- engines/scumm/string.cpp | 7 +++---- 3 files changed, 10 insertions(+), 12 deletions(-) (limited to 'engines') diff --git a/engines/scumm/imuse/imuse.cpp b/engines/scumm/imuse/imuse.cpp index 50a13308d8..1d52539ab5 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 b251e153cb..5e5c6ae351 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 9ea889c02b..a127de380e 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); } } -- cgit v1.2.3