Skip to content

Commit

Permalink
fix buffer overflow (by one value only) in spu that happened basicall…
Browse files Browse the repository at this point in the history
…y 100% of the time a sample ended. whether it corrupted the heap or not is a matter of luck. should fix #717
  • Loading branch information
zeromus committed Sep 3, 2023
1 parent 3955480 commit 25cbcd2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions desmume/src/SPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,6 @@ template<int FORMAT> static FORCEINLINE void TestForLoop(SPU_struct *SPU, channe
if(chan->repeat != 1)
{
SPU->KeyOff(chan->num);
SPU->bufpos = SPU->buflength;
return;
}

Expand Down Expand Up @@ -1235,13 +1234,16 @@ template<int FORMAT, SPUInterpolationMode INTERPOLATE_MODE, int CHANNELS>
{
s16 data = 0;
s32 pos = chan->sampcntInt;
switch(FORMAT)
if(chan->status != CHANSTAT_STOPPED)
{
case 0: data = Fetch8BitData (chan, pos); break;
case 1: data = Fetch16BitData(chan, pos); break;
case 2: data = FetchADPCMData(chan, pos); break;
case 3: data = FetchPSGData (chan, pos); break;
default: break;
switch(FORMAT)
{
case 0: data = Fetch8BitData (chan, pos); break;
case 1: data = Fetch16BitData(chan, pos); break;
case 2: data = FetchADPCMData(chan, pos); break;
case 3: data = FetchPSGData (chan, pos); break;
default: break;
}
}
chan->pcm16bOffs++;
chan->pcm16b[SPUCHAN_PCM16B_AT(chan->pcm16bOffs)] = data;
Expand Down

0 comments on commit 25cbcd2

Please sign in to comment.