CatacombSDL icon indicating copy to clipboard operation
CatacombSDL copied to clipboard

Overflow in `_SDL_turnOnPCSpeaker`

Open 64kramsystem opened this issue 2 years ago • 0 comments

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.

64kramsystem avatar Aug 14 '22 10:08 64kramsystem