mirror of https://github.com/snes9xgit/snes9x.git
win32: fix buffer overflows
This commit is contained in:
parent
1d57e214b3
commit
c90de1077b
|
@ -189,7 +189,7 @@ void CWaveOut::ProcessSound()
|
|||
UINT32 samplesleftinblock = (singleBufferBytes - partialOffset) >> 1;
|
||||
BYTE *offsetBuffer = (BYTE *)waveHeaders[writeOffset].lpData + partialOffset;
|
||||
|
||||
if (availableSamples <= samplesleftinblock)
|
||||
if (availableSamples < samplesleftinblock)
|
||||
{
|
||||
S9xMixSamples(offsetBuffer, availableSamples);
|
||||
partialOffset += availableSamples << 1;
|
||||
|
@ -217,7 +217,8 @@ void CWaveOut::ProcessSound()
|
|||
availableSamples -= singleBufferSamples;
|
||||
}
|
||||
|
||||
if (availableSamples > 0 && bufferCount < blockCount) {
|
||||
// need to check this is less than a single buffer, otherwise we have a race condition with bufferCount
|
||||
if (availableSamples > 0 && availableSamples < singleBufferSamples && bufferCount < blockCount) {
|
||||
S9xMixSamples((BYTE *)waveHeaders[writeOffset].lpData, availableSamples);
|
||||
partialOffset = availableSamples << 1;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <process.h>
|
||||
#include "dxerr.h"
|
||||
#include "commctrl.h"
|
||||
#include <assert.h>
|
||||
|
||||
/* CXAudio2
|
||||
Implements audio output through XAudio2.
|
||||
|
@ -322,13 +323,16 @@ void CXAudio2::ProcessSound()
|
|||
}
|
||||
|
||||
if (partialOffset != 0) {
|
||||
assert(partialOffset < singleBufferBytes);
|
||||
assert(bufferCount < blockCount);
|
||||
BYTE *offsetBuffer = soundBuffer + writeOffset + partialOffset;
|
||||
UINT32 samplesleftinblock = (singleBufferBytes - partialOffset) >> 1;
|
||||
|
||||
if (availableSamples <= samplesleftinblock)
|
||||
if (availableSamples < samplesleftinblock)
|
||||
{
|
||||
S9xMixSamples(offsetBuffer, availableSamples);
|
||||
partialOffset += availableSamples << 1;
|
||||
assert(partialOffset < singleBufferBytes);
|
||||
availableSamples = 0;
|
||||
}
|
||||
else
|
||||
|
@ -351,9 +355,11 @@ void CXAudio2::ProcessSound()
|
|||
availableSamples -= singleBufferSamples;
|
||||
}
|
||||
|
||||
if (availableSamples > 0 && bufferCount < blockCount) {
|
||||
// need to check this is less than a single buffer, otherwise we have a race condition with bufferCount
|
||||
if (availableSamples > 0 && availableSamples < singleBufferSamples && bufferCount < blockCount) {
|
||||
S9xMixSamples(soundBuffer + writeOffset, availableSamples);
|
||||
partialOffset = availableSamples << 1;
|
||||
assert(partialOffset < singleBufferBytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue