sagarpant1 / mame

Other
0 stars 1 forks source link

Potential issue in 3rdparty/portaudio/src/hostapi/wmme/pa_win_wmme.c: Arithmetic Overflow in Expression #1

Open monocle-ai opened 4 years ago

monocle-ai commented 4 years ago

What is a Arithmetic Overflow? When a narrow type integral value was shifted left, multiplied, added, or subtracted and the result of that arithmetic operation was cast to a wider type value. If the operation overflowed the narrow type value, then data is lost. You can prevent this loss by converting the value to a wider type before the arithmetic operation.

1 instance of this defect were found in the following locations:


Instance 1 File : 3rdparty/portaudio/src/hostapi/wmme/pa_win_wmme.c Enclosing Function : ProcessingThreadProc@4 https://github.com/sagarpant1/mame/blob/fe529afa8e0669d323dec9e3a575efc399009e5c/3rdparty/portaudio/src/hostapi/wmme/pa_win_wmme.c#L3028 Issue in: write position, frames in buffer ring

Code extract:

                                + stream->output.framesUsedInCurrentBuffer;

                        if( playbackPosition >= writePosition ){
                            timeInfo.outputBufferDacTime = <------ HERE
                                    time + ((double)( writePosition + (framesInBufferRing - playbackPosition) ) * stream->bufferProcessor.samplePeriod );
                        }else{

How can I fix it? Correct reference usage found in 3rdparty/portaudio/src/hostapi/wmme/pa_win_wmme.c at line 3031. https://github.com/sagarpant1/mame/blob/fe529afa8e0669d323dec9e3a575efc399009e5c/3rdparty/portaudio/src/hostapi/wmme/pa_win_wmme.c#L3031 Code extract:

                            timeInfo.outputBufferDacTime =
                                    time + ((double)( writePosition + (framesInBufferRing - playbackPosition) ) * stream->bufferProcessor.samplePeriod );
                        }else{
                            timeInfo.outputBufferDacTime = <------ HERE
                                    time + ((double)( writePosition - playbackPosition ) * stream->bufferProcessor.samplePeriod );
                        }