diff options
author | Colin Snover | 2016-08-28 20:56:29 -0500 |
---|---|---|
committer | Colin Snover | 2016-09-29 19:39:16 -0500 |
commit | 21ffb62f806b556a7faae84c5a221f51baa86087 (patch) | |
tree | b4eade8a77739b0276804ab1d2fb530168725247 /engines/sci/sound | |
parent | 78849053ca8abf203fe3f17972581416e86d334d (diff) | |
download | scummvm-rg350-21ffb62f806b556a7faae84c5a221f51baa86087.tar.gz scummvm-rg350-21ffb62f806b556a7faae84c5a221f51baa86087.tar.bz2 scummvm-rg350-21ffb62f806b556a7faae84c5a221f51baa86087.zip |
SCI32: Guard against dynamic_cast failure
CID 1361762, 1361763, 1361764, 1361765.
Diffstat (limited to 'engines/sci/sound')
-rw-r--r-- | engines/sci/sound/audio32.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/engines/sci/sound/audio32.cpp b/engines/sci/sound/audio32.cpp index 4af474b918..43c21939fa 100644 --- a/engines/sci/sound/audio32.cpp +++ b/engines/sci/sound/audio32.cpp @@ -183,6 +183,9 @@ int Audio32::writeAudioInternal(Audio::AudioStream *const sourceStream, Audio::R do { if (loop && sourceStream->endOfStream()) { Audio::RewindableAudioStream *rewindableStream = dynamic_cast<Audio::RewindableAudioStream *>(sourceStream); + if (rewindableStream == nullptr) { + error("[Audio32::writeAudioInternal]: Unable to cast stream"); + } rewindableStream->rewind(); } @@ -453,7 +456,11 @@ void Audio32::freeUnusedChannels() { const AudioChannel &channel = getChannel(channelIndex); if (!channel.robot && channel.stream->endOfStream()) { if (channel.loop) { - dynamic_cast<Audio::SeekableAudioStream *>(channel.stream)->rewind(); + Audio::SeekableAudioStream *stream = dynamic_cast<Audio::SeekableAudioStream *>(channel.stream); + if (stream == nullptr) { + error("[Audio32::freeUnusedChannels]: Unable to cast stream for resource %s", channel.id.toString().c_str()); + } + stream->rewind(); } else { stop(channelIndex--); } @@ -658,6 +665,9 @@ uint16 Audio32::play(int16 channelIndex, const ResourceId resourceId, const bool if (channelIndex != kNoExistingChannel) { AudioChannel &channel = getChannel(channelIndex); Audio::SeekableAudioStream *stream = dynamic_cast<Audio::SeekableAudioStream *>(channel.stream); + if (stream == nullptr) { + error("[Audio32::play]: Unable to cast stream for resource %s", resourceId.toString().c_str()); + } if (channel.pausedAtTick) { resume(channelIndex); @@ -764,7 +774,12 @@ uint16 Audio32::play(int16 channelIndex, const ResourceId resourceId, const bool // use audio streams, and allocate and fill the monitoring buffer // when reading audio data from the stream. - channel.duration = /* round up */ 1 + (dynamic_cast<Audio::SeekableAudioStream *>(channel.stream)->getLength().msecs() * 60 / 1000); + Audio::SeekableAudioStream *stream = dynamic_cast<Audio::SeekableAudioStream *>(channel.stream); + if (stream == nullptr) { + error("[Audio32::play]: Unable to cast stream for resource %s", resourceId.toString().c_str()); + } + + channel.duration = /* round up */ 1 + (stream->getLength().msecs() * 60 / 1000); const uint32 now = g_sci->getTickCount(); channel.pausedAtTick = autoPlay ? 0 : now; |