From d8af2e558fde7e494bd1f5b636f8989efb8391fb Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 31 Dec 2015 15:28:18 -0600 Subject: [PATCH] Fix potentiol buffer overrun in MUSSong2::Precache() --- src/sound/music_mus_midiout.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sound/music_mus_midiout.cpp b/src/sound/music_mus_midiout.cpp index eaf7e4afb..cc9bc1b69 100644 --- a/src/sound/music_mus_midiout.cpp +++ b/src/sound/music_mus_midiout.cpp @@ -211,11 +211,11 @@ bool MUSSong2::CheckDone() void MUSSong2::Precache() { - WORD *work = (WORD *)alloca(MusHeader->NumInstruments * sizeof(WORD)); + TArray work(MusHeader->NumInstruments); const BYTE *used = (BYTE *)MusHeader + sizeof(MUSHeader) / sizeof(BYTE); - int i, j, k; + int i, k; - for (i = j = k = 0; i < MusHeader->NumInstruments; ++i) + for (i = k = 0; i < MusHeader->NumInstruments; ++i) { BYTE instr = used[k++]; WORD val; @@ -240,15 +240,15 @@ void MUSSong2::Precache() { for (int b = 0; b < numbanks; b++) { - work[j++] = val | (used[k++] << 7); + work.Push(val | (used[k++] << 7)); } } else { - work[j++] = val; + work.Push(val); } } - MIDI->PrecacheInstruments(&work[0], j); + MIDI->PrecacheInstruments(&work[0], work.Size()); } //==========================================================================