aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2008-01-20 13:27:54 -0800
committerChris Robinson <[email protected]>2008-01-20 13:27:54 -0800
commit6bf6c6fb7b984a73634765d0c935814bc6cc71ed (patch)
treea78e6d577d18aed532fe1275a5fd07d284325ade /OpenAL32
parent29618bee10215d1de2111ad35000c4bf5d779113 (diff)
More overflow protection
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/alBuffer.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c
index a6eda9d3..84f29508 100644
--- a/OpenAL32/alBuffer.c
+++ b/OpenAL32/alBuffer.c
@@ -371,12 +371,19 @@ ALAPI ALvoid ALAPIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid *d
ALBuf->data = realloc(ALBuf->data, (8*NewChannels + size) * (1*sizeof(ALshort)));
if (ALBuf->data)
{
+ ALint smp;
for (i = 0;i < size;i+=4)
{
ALBuf->data[i+0] = 0;
ALBuf->data[i+1] = 0;
- ALBuf->data[i+2] = (ALshort)(((ALfloat*)data)[i/2+0] * 32767.5f - 0.5);
- ALBuf->data[i+3] = (ALshort)(((ALfloat*)data)[i/2+1] * 32767.5f - 0.5);
+ smp = (((ALfloat*)data)[i/2+0] * 32767.5f - 0.5);
+ smp = min(smp, 32767);
+ smp = max(smp, -32768);
+ ALBuf->data[i+2] = (ALshort)smp;
+ smp = (((ALfloat*)data)[i/2+1] * 32767.5f - 0.5);
+ smp = min(smp, 32767);
+ smp = max(smp, -32768);
+ ALBuf->data[i+3] = (ALshort)smp;
}
memset(&(ALBuf->data[size]), 0, 16*NewChannels);