Commit be32dc0e authored by Jan Polák's avatar Jan Polák Committed by David Reid

Fix UB when there are no audio devices

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.
parent 0c92dac8
...@@ -39913,7 +39913,12 @@ MA_API ma_result ma_context_get_devices(ma_context* pContext, ma_device_info** p ...@@ -39913,7 +39913,12 @@ MA_API ma_result ma_context_get_devices(ma_context* pContext, ma_device_info** p
/* Capture devices. */ /* Capture devices. */
if (ppCaptureDeviceInfos != NULL) { if (ppCaptureDeviceInfos != NULL) {
*ppCaptureDeviceInfos = pContext->pDeviceInfos + pContext->playbackDeviceInfoCount; /* Capture devices come after playback devices. */ *ppCaptureDeviceInfos = pContext->pDeviceInfos;
/* Capture devices come after playback devices. */
if (pContext->playbackDeviceInfoCount > 0) {
/* Conditional, because NULL+0 is undefined behavior. */
*ppCaptureDeviceInfos += pContext->playbackDeviceInfoCount;
}
} }
if (pCaptureDeviceCount != NULL) { if (pCaptureDeviceCount != NULL) {
*pCaptureDeviceCount = pContext->captureDeviceInfoCount; *pCaptureDeviceCount = pContext->captureDeviceInfoCount;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment