CatacombSDL
CatacombSDL copied to clipboard
Overflow in `_SDL_turnOnPCSpeaker`
The _SDL_turnOnPCSpeaker
function performs this operation:
pcPhaseLength = (pcSample*AudioSpec.freq)/(2*PC_BASE_TIMER);
now, pcSample
is a 16 bit unsigned, and AudioSpec.freq
a 32 bit signed; their product yields a 32 bit signed.
Since pcSample
does reach a value of 65535, and AudioSpec.freq
can be 48000, the result will overflow the 32 bit signed capacity.
I guess that one of the two should be casted to a 32 bit unsigned, which, conveniently, is also the pcPhaseLength
size.
Snippet here.