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.
This commit is contained in:
D G Turner 2019-09-15 20:20:03 +01:00
parent 34f3e8667c
commit 84d0a294af
3 changed files with 10 additions and 12 deletions

View File

@ -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];

View File

@ -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);
}

View File

@ -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);
}
}