PortAudio / portaudio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.
Other
1.45k stars 303 forks source link

Assert may not have been a NOOP #962

Open philburk opened 6 days ago

philburk commented 6 days ago

In a review of a WASAPI change I stated that an assert was a NOOP.

_Originally posted by @philburk in https://github.com/PortAudio/portaudio/pull/948#discussion_r1768861142_

But after rereading the code I realize that I misread line 1425. I thought it was checking "subtream->monoBuffer". But it was checking "subtream->monoMixer". So the assert(subtream->monoBuffer != NULL) actually did something.

If Dmitry wants to add it back in that is fine with me.

dmitrykos commented 6 days ago

I replaced this assert with a new one to assert the reason rather than consequence to assist the understanding of the logic:

https://github.com/PortAudio/portaudio/blob/c1214824ab5b8e2229654aa737e7435782fd56d9/src/hostapi/wasapi/pa_win_wasapi.c#L1432

subtream->monoBuffer can become NULL in that piece of logic only if this condition fails when monoBufferSize is 0 because initially subStream->monoBufferSize is 0 and it is set only inside this function when monoBuffer is allocated successfully:

https://github.com/PortAudio/portaudio/blob/c1214824ab5b8e2229654aa737e7435782fd56d9/src/hostapi/wasapi/pa_win_wasapi.c#L1435-L1436

but it will not happen if frames and nBlockAlign are not 0. So for now I think assert(subtream->monoBuffer != NULL) is no longer needed.