From 45308a2bd5e2aa0cff92375fac877a0b1a166d93 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 3 Nov 2009 20:49:53 +0000 Subject: Fix for bug #2890038 (FT: Crashes when entering inventory) svn-id: r45638 --- sound/audiostream.cpp | 2 ++ sound/voc.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'sound') diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index 783a5733b3..7d3cf935aa 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -220,6 +220,8 @@ public: : _rate(rate), _stream(stream), _beginLoop(beginLoop), _endLoop(endLoop), _disposeAfterUse(disposeStream), _audioBlockCount(numBlocks), _loop(loop) { + assert(numBlocks > 0); + // Allocate streaming buffer if (is16Bit) { _buffer = (byte *)malloc(BUFFER_SIZE * sizeof(int16)); diff --git a/sound/voc.cpp b/sound/voc.cpp index 9179f5e7e5..5db32693eb 100644 --- a/sound/voc.cpp +++ b/sound/voc.cpp @@ -180,7 +180,6 @@ int parseVOCFormat(Common::SeekableReadStream& stream, LinearDiskStreamAudioBloc debug(2, "parseVOCFormat"); - if (stream.read(&fileHeader, 8) != 8) goto invalid; @@ -301,7 +300,12 @@ AudioStream *makeVOCDiskStream(Common::SeekableReadStream &stream, byte flags, b int numBlocks = parseVOCFormat(stream, block, rate, loops, begin_loop, end_loop); - AudioStream *audioStream = makeLinearDiskStream(&stream, block, numBlocks, rate, flags, takeOwnership, begin_loop, end_loop); + AudioStream *audioStream = 0; + + // Create an audiostream from the data. Note the numBlocks may be 0, + // e.g. when invalid data is encountered. See bug #2890038. + if (numBlocks) + audioStream = makeLinearDiskStream(&stream, block, numBlocks, rate, flags, takeOwnership, begin_loop, end_loop); delete[] block; -- cgit v1.2.3