aboutsummaryrefslogtreecommitdiff
path: root/engines/hdb
diff options
context:
space:
mode:
authorD G Turner2019-09-13 20:14:22 +0100
committerD G Turner2019-09-13 20:14:22 +0100
commitec677b3fe9eafe5de2a36e50efb44e1384150820 (patch)
treecde53fe6ddf8e7cca4a4b25e6447a948fcb59c50 /engines/hdb
parentac3586eb9a879f9be0b4ae603a0c229d6eee9ef5 (diff)
downloadscummvm-rg350-ec677b3fe9eafe5de2a36e50efb44e1384150820.tar.gz
scummvm-rg350-ec677b3fe9eafe5de2a36e50efb44e1384150820.tar.bz2
scummvm-rg350-ec677b3fe9eafe5de2a36e50efb44e1384150820.zip
HDB: Fix Crash on Invalid Sound String Pointers
This was causing a crash with buffer overflow on Windows builds, but diagnosing with Valgrind showed invalid strings being accessed in the sound code. Some analysis showed that these were mainly the reference to c_str() buffers from a local heap Common::String which was out of scope and thus destructed, giving an invalid pointer. The fix here also simplifies the code as well as avoiding this issue.
Diffstat (limited to 'engines/hdb')
-rw-r--r--engines/hdb/sound.cpp9
1 files changed, 3 insertions, 6 deletions
diff --git a/engines/hdb/sound.cpp b/engines/hdb/sound.cpp
index 0f8fc8df6c..d2c27961a9 100644
--- a/engines/hdb/sound.cpp
+++ b/engines/hdb/sound.cpp
@@ -1755,14 +1755,11 @@ void Sound::stopMusic() {
}
void Sound::beginMusic(SoundType song, bool fadeIn, int ramp) {
- const char *songName = nullptr;
+ Common::String songName(soundList[song].name);
if (g_hdb->getPlatform() == Common::kPlatformLinux) {
- Common::String updatedName(soundList[song].name);
- updatedName.replace(updatedName.begin() + updatedName.size() - 4, updatedName.end(), ".ogg");
- songName = updatedName.c_str();
- } else
- songName = soundList[song].name;
+ songName.replace(songName.begin() + songName.size() - 4, songName.end(), ".ogg");
+ }
if (g_hdb->isPPC()) {
switch (song) {