aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorFilippos Karapetis2010-08-24 13:31:44 +0000
committerFilippos Karapetis2010-08-24 13:31:44 +0000
commit83c8ed97e3e5204e408e4ec8b73068142891ea25 (patch)
treeac29714b5e9eddc7b0c52a4606fed7af0a239e7c /engines
parent2d615944fb82cdc40b385c22993a00d09902268a (diff)
downloadscummvm-rg350-83c8ed97e3e5204e408e4ec8b73068142891ea25.tar.gz
scummvm-rg350-83c8ed97e3e5204e408e4ec8b73068142891ea25.tar.bz2
scummvm-rg350-83c8ed97e3e5204e408e4ec8b73068142891ea25.zip
TINSEL: Code cleanup, fixed potentially undefined behavior
svn-id: r52338
Diffstat (limited to 'engines')
-rw-r--r--engines/tinsel/music.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/engines/tinsel/music.cpp b/engines/tinsel/music.cpp
index c360e2466a..ea34fa963a 100644
--- a/engines/tinsel/music.cpp
+++ b/engines/tinsel/music.cpp
@@ -361,7 +361,7 @@ void OpenMidiFiles() {
// Now scan through the contents of the MIDI file to find the offset
// of each individual track, in order to create a mapping from MIDI
- // offset to track number, for the enhanced MIDI soundtrack
+ // offset to track number, for the enhanced MIDI soundtrack.
// The first song is always at position 4. The subsequent ones are
// calculated dynamically.
uint32 curOffset = 4;
@@ -373,16 +373,18 @@ void OpenMidiFiles() {
midiOffsets[i] = 0;
while (!midiStream.eos() && !midiStream.err()) {
+ if (curOffset + (4 * curTrack) >= (uint32)midiStream.size())
+ break;
+
assert(curTrack < ARRAYSIZE(midiOffsets));
- midiOffsets[curTrack++] = curOffset + (4 * curTrack);
- //printf("%d: %d\n", curTrack - 1, midiOffsets[curTrack - 1]);
+ midiOffsets[curTrack] = curOffset + (4 * curTrack);
+ //printf("%d: %d\n", curTrack, midiOffsets[curTrack]);
songLength = midiStream.readUint32LE();
curOffset += songLength;
midiStream.skip(songLength);
- if (curOffset + (4 * curTrack) >= (uint32)midiStream.size())
- break;
+ curTrack++;
}
midiStream.close();