DRACI: Allocate no-sound buffer on the heap in LegacySoundArchive::openArchive()

This commit is contained in:
Julien 2011-06-06 01:10:09 +08:00 committed by Julien
parent 9ff993382e
commit e610a17fc3

View File

@ -67,8 +67,12 @@ void LegacySoundArchive::openArchive(const char *path) {
debugC(1, kDraciArchiverDebugLevel, "Loading header");
uint totalLength = _f->readUint32LE();
const uint kMaxSamples = 4095; // The no-sound file is exactly 16K bytes long, so don't fail on short reads
uint sampleStarts[kMaxSamples];
uint *sampleStarts = (uint *)malloc(kMaxSamples * sizeof(uint));
if (!sampleStarts)
error("[LegacySoundArchive::openArchive] Cannot allocate buffer for no-sound file");
for (uint i = 0; i < kMaxSamples; ++i) {
sampleStarts[i] = _f->readUint32LE();
}
@ -90,17 +94,22 @@ void LegacySoundArchive::openArchive(const char *path) {
}
if (_samples[_sampleCount-1]._offset + _samples[_sampleCount-1]._length != totalLength &&
_samples[_sampleCount-1]._offset + _samples[_sampleCount-1]._length - _samples[0]._offset != totalLength) {
// WORKAROUND: the stored length is stored with the header for sounds and without the hader for dubbing. Crazy.
// WORKAROUND: the stored length is stored with the header for sounds and without the header for dubbing. Crazy.
debugC(1, kDraciArchiverDebugLevel, "Broken sound archive: %d != %d",
_samples[_sampleCount-1]._offset + _samples[_sampleCount-1]._length,
totalLength);
closeArchive();
free(sampleStarts);
return;
}
} else {
debugC(1, kDraciArchiverDebugLevel, "Archive info: empty");
}
free(sampleStarts);
// Indicate that the archive has been successfully opened
_opened = true;
}