Skip to content

Commit

Permalink
audio: Code defensively to placate static analyzers, don't disabling …
Browse files Browse the repository at this point in the history
…warnings.
  • Loading branch information
icculus committed Apr 16, 2024
1 parent bdd47f7 commit 12b3716
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions src/audio/SDL_audio.c
Expand Up @@ -1811,7 +1811,8 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int
for (int i = 0; i < num_streams; i++) {
SDL_AudioStream *stream = streams[i];
if (!stream) {
retval = SDL_SetError("Stream #%d is NULL", i);
SDL_SetError("Stream #%d is NULL", i);
retval = -1; // to pacify the static analyzer, that doesn't realize SDL_SetError() always returns -1.
} else {
SDL_LockMutex(stream->lock);
SDL_assert((stream->bound_device == NULL) == ((stream->prev_binding == NULL) || (stream->next_binding == NULL)));
Expand Down Expand Up @@ -1839,31 +1840,25 @@ 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];
if (stream) { // shouldn't be NULL, but just in case...
stream->bound_device = logdev;
stream->prev_binding = NULL;
stream->next_binding = logdev->bound_streams;
if (logdev->bound_streams) {
logdev->bound_streams->prev_binding = stream;
}
logdev->bound_streams = stream;

stream->bound_device = logdev;
stream->prev_binding = NULL;
stream->next_binding = logdev->bound_streams;
if (logdev->bound_streams) {
logdev->bound_streams->prev_binding = stream;
}
logdev->bound_streams = stream;

if (iscapture) {
SDL_copyp(&stream->src_spec, &device->spec);
if (logdev->postmix) {
stream->src_spec.format = SDL_AUDIO_F32;
if (iscapture) {
SDL_copyp(&stream->src_spec, &device->spec);
if (logdev->postmix) {
stream->src_spec.format = SDL_AUDIO_F32;
}
}
}

SDL_UnlockMutex(stream->lock);
#ifdef _MSC_VER
#pragma warning(pop)
#endif
SDL_UnlockMutex(stream->lock);
}
}
}

Expand Down

0 comments on commit 12b3716

Please sign in to comment.