Browse Source

Fixed warning C28182: Dereferencing NULL pointer. 'streams[j]' contains the same NULL value as 'stream' did.

Sam Lantinga 1 year ago
parent
commit
226f8fde09
1 changed files with 14 additions and 0 deletions
  1. 14 0
      src/audio/SDL_audio.c

+ 14 - 0
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
         }
     }