aboutsummaryrefslogtreecommitdiff
path: root/sword1
diff options
context:
space:
mode:
authorTorbjörn Andersson2004-10-30 10:35:39 +0000
committerTorbjörn Andersson2004-10-30 10:35:39 +0000
commit94d74a04e98828603bdcfc7f8cfaa76e2349a947 (patch)
treee9439497c067f1d0bdd37610e13f2bc913effea2 /sword1
parentafc07026c68d21dd3dc7d9723da5e1df0497590f (diff)
downloadscummvm-rg350-94d74a04e98828603bdcfc7f8cfaa76e2349a947.tar.gz
scummvm-rg350-94d74a04e98828603bdcfc7f8cfaa76e2349a947.tar.bz2
scummvm-rg350-94d74a04e98828603bdcfc7f8cfaa76e2349a947.zip
Brute-force workaround for speech decoder crashes in the BS1 demo. It still
doesn't work very well, though... svn-id: r15697
Diffstat (limited to 'sword1')
-rw-r--r--sword1/sound.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/sword1/sound.cpp b/sword1/sound.cpp
index f3fcdcb5cf..f33f1cf36c 100644
--- a/sword1/sound.cpp
+++ b/sword1/sound.cpp
@@ -214,20 +214,40 @@ int16 *Sound::uncompressSpeech(uint32 index, uint32 cSize, uint32 *size) {
} else
resSize = READ_LE_UINT32(fBuf + headerPos + 4) >> 1;
int16 *srcData = (int16*)(fBuf + headerPos + 8);
- int16 *dstData = (int16*)malloc(resSize * 2);
uint32 srcPos = 0;
- int16 *dstPos = dstData;
+ uint32 dstPos = 0;
cSize = (cSize - (headerPos + 8)) / 2;
+ if (_cowMode == CowDemo) {
+ // FIXME: Until someone figures out how to really
+ // calculate the uncompressed buffer size, use
+ // brute force to avoid crashes.
+ debug(1, "old resSize = %d", resSize);
+ resSize = 0;
+ while (srcPos < cSize) {
+ int16 length = (int16)READ_LE_UINT16(srcData + srcPos);
+ srcPos++;
+ if (length < 0) {
+ length = -length;
+ srcPos++;
+ } else {
+ srcPos += length;
+ }
+ resSize += length;
+ }
+ debug(1, "new resSize = %d", resSize);
+ }
+ int16 *dstData = (int16*)malloc(resSize * 2);
+ srcPos = 0;
while (srcPos < cSize) {
int16 length = (int16)READ_LE_UINT16(srcData + srcPos);
srcPos++;
if (length < 0) {
length = -length;
for (uint16 cnt = 0; cnt < (uint16)length; cnt++)
- *dstPos++ = srcData[srcPos];
+ dstData[dstPos++] = srcData[srcPos];
srcPos++;
} else {
- memcpy(dstPos, srcData + srcPos, length * 2);
+ memcpy(dstData + dstPos, srcData + srcPos, length * 2);
dstPos += length;
srcPos += length;
}