Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UB when there are no audio devices #531

Merged
merged 1 commit into from
Sep 2, 2022
Merged

Conversation

Darkyenus
Copy link

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.

Some extra context: SO about NULL arithmetic and Zig issue about the same problem elsewhere.

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.
@mackron mackron merged commit be32dc0 into mackron:dev Sep 2, 2022
@mackron
Copy link
Owner

mackron commented Sep 2, 2022

This is reasonable. Merged. Thanks!

@Darkyenus Darkyenus deleted the fix-ub branch September 5, 2022 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants