mirror of
https://github.com/RetroDECK/Supermodel.git
synced 2024-11-22 13:55:38 +00:00
Fix possible negative pointer arithmetic which was causing the music to wrap around.
This commit is contained in:
parent
a76e46e3b8
commit
cc830003f5
|
@ -7,7 +7,7 @@ struct Decoder
|
||||||
mp3dec_t mp3d;
|
mp3dec_t mp3d;
|
||||||
mp3dec_frame_info_t info;
|
mp3dec_frame_info_t info;
|
||||||
const uint8_t* buffer;
|
const uint8_t* buffer;
|
||||||
size_t size, pos;
|
int size, pos;
|
||||||
bool loop;
|
bool loop;
|
||||||
bool stopped;
|
bool stopped;
|
||||||
int numSamples;
|
int numSamples;
|
||||||
|
@ -32,11 +32,17 @@ void MpegDec::SetMemory(const uint8_t *data, int length, bool loop)
|
||||||
|
|
||||||
void MpegDec::UpdateMemory(const uint8_t* data, int length, bool loop)
|
void MpegDec::UpdateMemory(const uint8_t* data, int length, bool loop)
|
||||||
{
|
{
|
||||||
auto pos = dec.buffer + dec.pos;
|
int diff;
|
||||||
|
if (data > dec.buffer) {
|
||||||
|
diff = (int)(data - dec.buffer);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
diff = -(int)(dec.buffer - data);
|
||||||
|
}
|
||||||
|
|
||||||
dec.buffer = data;
|
dec.buffer = data;
|
||||||
dec.size = length;
|
dec.size = length;
|
||||||
dec.pos = pos - dec.buffer; // update position relative to our new start location
|
dec.pos = dec.pos - diff; // update position relative to our new start location
|
||||||
dec.loop = loop;
|
dec.loop = loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue