When there are no capture nor playback devices, pContext->pDeviceInfos is NULL and pContext->playbackDeviceInfoCount is 0. Unfortunately, any arithmetic on NULL is UB, including trivial +0, which triggers UB sanitizer. This can lead to crashes, for example when compiling with Zig, which enables UBsan by default.
Note: this could easily be a oneliner, but the line was already long enough.
I have also wanted to include an explicit comment, because without knowing that NULL+0 is UB, the code would seem insane.
When there are no capture nor playback devices,
pContext->pDeviceInfos
isNULL
andpContext->playbackDeviceInfoCount
is 0. Unfortunately, any arithmetic onNULL
is UB, including trivial+0
, which triggers UB sanitizer. This can lead to crashes, for example when compiling with Zig, which enables UBsan by default.Note: this could easily be a oneliner, but the line was already long enough. I have also wanted to include an explicit comment, because without knowing that
NULL+0
is UB, the code would seem insane.Some extra context: SO about NULL arithmetic and Zig issue about the same problem elsewhere.