mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
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.
This commit is contained in:
+6
-1
@@ -39913,7 +39913,12 @@ MA_API ma_result ma_context_get_devices(ma_context* pContext, ma_device_info** p
|
||||
|
||||
/* Capture devices. */
|
||||
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) {
|
||||
*pCaptureDeviceCount = pContext->captureDeviceInfoCount;
|
||||
|
||||
Reference in New Issue
Block a user