From 226f8fde09fdc315730fc64e18ad2653bc24dac2 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 4 Dec 2023 19:43:41 -0800
Subject: [PATCH] Fixed warning C28182: Dereferencing NULL pointer.
'streams[j]' contains the same NULL value as 'stream' did.
---
src/audio/SDL_audio.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index b47c840b6b54..54f74d89b144 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -1771,7 +1771,14 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int
if (retval != 0) {
int j;
for (j = 0; j <= i; j++) {
+#ifdef _MSC_VER /* Visual Studio analyzer can't tell that we've already verified streams[j] isn't NULL */
+#pragma warning(push)
+#pragma warning(disable : 28182)
+#endif
SDL_UnlockMutex(streams[j]->lock);
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
}
break;
}
@@ -1782,6 +1789,10 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int
// Now that everything is verified, chain everything together.
const SDL_bool iscapture = device->iscapture;
for (int i = 0; i < num_streams; i++) {
+#ifdef _MSC_VER /* Visual Studio analyzer can't tell that streams[i] isn't NULL if retval is 0 */
+#pragma warning(push)
+#pragma warning(disable : 28182)
+#endif
SDL_AudioStream *stream = streams[i];
stream->bound_device = logdev;
@@ -1800,6 +1811,9 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int
}
SDL_UnlockMutex(stream->lock);
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
}
}