diff options
author | Martin Kiewitz | 2015-07-03 02:05:26 +0200 |
---|---|---|
committer | Martin Kiewitz | 2015-07-03 02:05:26 +0200 |
commit | 04146fc9b399f99165ff71e609450378f6928847 (patch) | |
tree | 470ccdc2caa2f246dd9c6ee37dfef7523217fc13 | |
parent | 453a800754dcc512247d0daa768c866e929f291a (diff) | |
download | scummvm-rg350-04146fc9b399f99165ff71e609450378f6928847.tar.gz scummvm-rg350-04146fc9b399f99165ff71e609450378f6928847.tar.bz2 scummvm-rg350-04146fc9b399f99165ff71e609450378f6928847.zip |
AUDIO: Miles Audio AdLib: fix instrument load code
clean up, uses separate non-const pointer for reading file
and a const pointer for actually parsing the data
-rw-r--r-- | audio/miles_adlib.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/audio/miles_adlib.cpp b/audio/miles_adlib.cpp index e45fa4e76f..90c2c4b3f5 100644 --- a/audio/miles_adlib.cpp +++ b/audio/miles_adlib.cpp @@ -1064,17 +1064,17 @@ MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String instrumentDataFil // Load adlib instrument data from file SAMPLE.AD (OPL3: SAMPLE.OPL) Common::File *fileStream = NULL; uint32 fileSize = 0; - const byte *fileDataPtr = NULL; - bool fileDataAllocatedByUs = false; + byte *fileDataReadPtr = nullptr; + const byte *fileDataPtr = nullptr; uint32 fileDataOffset = 0; uint32 fileDataLeft = 0; byte curBankId = 0; byte curPatchId = 0; - InstrumentEntry *instrumentTablePtr = NULL; + InstrumentEntry *instrumentTablePtr = nullptr; uint16 instrumentTableCount = 0; - InstrumentEntry *instrumentPtr = NULL; + InstrumentEntry *instrumentPtr = nullptr; uint32 instrumentOffset = 0; uint16 instrumentDataSize = 0; @@ -1087,14 +1087,15 @@ MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String instrumentDataFil fileSize = fileStream->size(); - fileDataPtr = new byte[fileSize]; - fileDataAllocatedByUs = true; + fileDataReadPtr = new byte[fileSize]; - if (fileStream->read((byte *)fileDataPtr, fileSize) != fileSize) + if (fileStream->read(fileDataReadPtr, fileSize) != fileSize) error("MILES-ADLIB: error while reading instrument file"); fileStream->close(); delete fileStream; + fileDataPtr = fileDataReadPtr; + } else if (instrumentRawDataPtr) { // instrument data was passed directly (currently used by Amazon Guardians of Eden fileDataPtr = instrumentRawDataPtr; @@ -1168,9 +1169,9 @@ MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String instrumentDataFil instrumentPtr++; } - if (fileDataAllocatedByUs) { - // Free instrument file data - delete[] fileDataPtr; + if (fileDataReadPtr) { + // Free instrument file data in case it was read by us + delete[] fileDataReadPtr; } return new MidiDriver_Miles_AdLib(g_system->getMixer(), instrumentTablePtr, instrumentTableCount); |