foxygit / doom Log in
commit dc7d72797f1d6810b8ba2f8472f6828f1f714df6
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sun Oct 5 18:29:37 2008 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sun Oct 5 18:29:37 2008 +0000

    Perform bounds checking on separation and volume values passed to the
    low-level sound code, as the Heretic s_sound.c code generates values
    that are out of range.

    Subversion-branch: /branches/raven-branch
    Subversion-revision: 1337
---
 src/i_sound.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/i_sound.c b/src/i_sound.c
index 2a29ccff..439f8689 100644
--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -249,10 +249,32 @@ void I_UpdateSound(void)
     }
 }

+static void CheckVolumeSeparation(int *sep, int *vol)
+{
+    if (*sep < 0)
+    {
+        *sep = 0;
+    }
+    else if (*sep > 254)
+    {
+        *sep = 254;
+    }
+
+    if (*vol < 0)
+    {
+        *vol = 0;
+    }
+    else if (*vol > 127)
+    {
+        *vol = 127;
+    }
+}
+
 void I_UpdateSoundParams(int channel, int vol, int sep)
 {
     if (sound_module != NULL)
     {
+        CheckVolumeSeparation(&vol, &sep);
         sound_module->UpdateSoundParams(channel, vol, sep);
     }
 }
@@ -261,6 +283,7 @@ int I_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep)
 {
     if (sound_module != NULL)
     {
+        CheckVolumeSeparation(&vol, &sep);
         return sound_module->StartSound(sfxinfo, channel, vol, sep);
     }
     else