foxygit / doom Log in
commit f894f24bcd63dc8b2a0604a9b659dd95aebbb384
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sun Sep 20 21:19:37 2009 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sun Sep 20 21:19:37 2009 +0000

    Avoid possible overflow due to base note offset.

    Subversion-branch: /branches/opl-branch
    Subversion-revision: 1683
---
 src/i_oplmusic.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c
index de126c63..aa079614 100644
--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -934,6 +934,13 @@ static unsigned int FrequencyForVoice(opl_voice_t *voice)
     gm_voice = &voice->current_instr->voices[voice->current_instr_voice];
     note += (signed short) SHORT(gm_voice->base_note_offset);

+    // Avoid possible overflow due to base note offset:
+
+    if (note > 0x7f)
+    {
+        note = voice->note;
+    }
+
     freq_index = 64 + 32 * note + voice->channel->bend;

     // If this is the second voice of a double voice instrument, the