SDL_mixer: Initialize SDL_AudioSpec before using it to create an audio stream

From b18d7b3b2829e7f760bcb402621a75842ee5e530 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 4 Jul 2024 11:51:34 -0700
Subject: [PATCH] Initialize SDL_AudioSpec before using it to create an audio
 stream

---
 src/codecs/music_drflac.c     | 1 +
 src/codecs/music_flac.c       | 1 +
 src/codecs/music_fluidsynth.c | 1 +
 src/codecs/music_gme.c        | 1 +
 src/codecs/music_minimp3.c    | 1 +
 src/codecs/music_modplug.c    | 1 +
 src/codecs/music_mpg123.c     | 2 ++
 src/codecs/music_ogg.c        | 1 +
 src/codecs/music_ogg_stb.c    | 1 +
 src/codecs/music_opus.c       | 1 +
 src/codecs/music_wavpack.c    | 1 +
 src/codecs/music_xmp.c        | 1 +
 src/mixer.c                   | 1 +
 13 files changed, 14 insertions(+)

diff --git a/src/codecs/music_drflac.c b/src/codecs/music_drflac.c
index d00900b9..bc8738a4 100644
--- a/src/codecs/music_drflac.c
+++ b/src/codecs/music_drflac.c
@@ -184,6 +184,7 @@ static void *DRFLAC_CreateFromIO(SDL_IOStream *src, SDL_bool closeio)
     }
 
     /* We should have channels and sample rate set up here */
+    SDL_zero(srcspec);
     srcspec.format = SDL_AUDIO_S16;
     srcspec.channels = music->channels;
     srcspec.freq = music->sample_rate;
diff --git a/src/codecs/music_flac.c b/src/codecs/music_flac.c
index 87c03604..ac557f26 100644
--- a/src/codecs/music_flac.c
+++ b/src/codecs/music_flac.c
@@ -421,6 +421,7 @@ static void flac_metadata_music_cb(
 
         /* We check for NULL stream later when we get data */
         SDL_assert(!music->stream);
+        SDL_zero(srcspec);
         srcspec.format = SDL_AUDIO_S16;
         srcspec.channels = channels;
         srcspec.freq = (int)music->sample_rate;
diff --git a/src/codecs/music_fluidsynth.c b/src/codecs/music_fluidsynth.c
index c92bdb0d..268ece48 100644
--- a/src/codecs/music_fluidsynth.c
+++ b/src/codecs/music_fluidsynth.c
@@ -234,6 +234,7 @@ static FLUIDSYNTH_Music *FLUIDSYNTH_LoadMusic(void *data)
         goto fail;
     }
 
+    SDL_zero(srcspec);
     srcspec.format = src_format;
     srcspec.channels = channels;
     srcspec.freq = (int) samplerate;
diff --git a/src/codecs/music_gme.c b/src/codecs/music_gme.c
index e988a466..7a7cd5c3 100644
--- a/src/codecs/music_gme.c
+++ b/src/codecs/music_gme.c
@@ -218,6 +218,7 @@ static void *GME_CreateFromIO(struct SDL_IOStream *src, SDL_bool closeio)
     music->tempo = 1.0;
     music->gain = 1.0;
 
+    SDL_zero(srcspec);
     srcspec.format = SDL_AUDIO_S16;
     srcspec.channels = 2;
     srcspec.freq = music_spec.freq;
diff --git a/src/codecs/music_minimp3.c b/src/codecs/music_minimp3.c
index 30cbd4db..a22d6c6e 100644
--- a/src/codecs/music_minimp3.c
+++ b/src/codecs/music_minimp3.c
@@ -100,6 +100,7 @@ static void *MINIMP3_CreateFromIO(SDL_IOStream *src, SDL_bool closeio)
         return NULL;
     }
 
+    SDL_zero(file_spec);
     file_spec.format = SDL_AUDIO_S16;
     file_spec.channels = (Uint8)music->dec.info.channels;
     file_spec.freq = (int)music->dec.info.hz;
diff --git a/src/codecs/music_modplug.c b/src/codecs/music_modplug.c
index 806cf0db..7a9c586c 100644
--- a/src/codecs/music_modplug.c
+++ b/src/codecs/music_modplug.c
@@ -179,6 +179,7 @@ void *MODPLUG_CreateFromIO(SDL_IOStream *src, SDL_bool closeio)
 
     music->volume = MIX_MAX_VOLUME;
 
+    SDL_zero(srcspec);
     srcspec.format = (settings.mBits == 8) ? SDL_AUDIO_U8 : SDL_AUDIO_S16;
     srcspec.channels = settings.mChannels;
     srcspec.freq = settings.mFrequency;
diff --git a/src/codecs/music_mpg123.c b/src/codecs/music_mpg123.c
index 3264745a..6ea0f216 100644
--- a/src/codecs/music_mpg123.c
+++ b/src/codecs/music_mpg123.c
@@ -322,6 +322,7 @@ static void *MPG123_CreateFromIO(SDL_IOStream *src, SDL_bool closeio)
     SDL_assert(format != -1);
     music->sample_rate = rate;
 
+    SDL_zero(srcspec);
     srcspec.format = (SDL_AudioFormat)format;
     srcspec.channels = channels;
     srcspec.freq = (int)rate;
@@ -410,6 +411,7 @@ static int MPG123_GetSome(void *context, void *data, int bytes, SDL_bool *done)
             SDL_DestroyAudioStream(music->stream);
         }
 
+        SDL_zero(srcspec);
         srcspec.format = (SDL_AudioFormat)format;
         srcspec.channels = channels;
         srcspec.freq = (int)rate;
diff --git a/src/codecs/music_ogg.c b/src/codecs/music_ogg.c
index 63963b23..459a5cf1 100644
--- a/src/codecs/music_ogg.c
+++ b/src/codecs/music_ogg.c
@@ -220,6 +220,7 @@ static int OGG_UpdateSection(OGG_music *music)
         music->stream = NULL;
     }
 
+    SDL_zero(srcspec);
     srcspec.format = SDL_AUDIO_S16;
     srcspec.channels = vi->channels;
     srcspec.freq = (int)vi->rate;
diff --git a/src/codecs/music_ogg_stb.c b/src/codecs/music_ogg_stb.c
index 0590d88d..cab061ec 100644
--- a/src/codecs/music_ogg_stb.c
+++ b/src/codecs/music_ogg_stb.c
@@ -142,6 +142,7 @@ static int OGG_UpdateSection(OGG_music *music)
         music->stream = NULL;
     }
 
+    SDL_zero(srcspec);
     srcspec.format = SDL_AUDIO_F32;
     srcspec.channels = vi.channels;
     srcspec.freq = (int)vi.sample_rate;
diff --git a/src/codecs/music_opus.c b/src/codecs/music_opus.c
index 3fdf9c8b..ce394445 100644
--- a/src/codecs/music_opus.c
+++ b/src/codecs/music_opus.c
@@ -191,6 +191,7 @@ static int OPUS_UpdateSection(OPUS_music *music)
         music->stream = NULL;
     }
 
+    SDL_zero(srcspec);
     srcspec.format = SDL_AUDIO_S16;
     srcspec.channels = op_info->channel_count;
     srcspec.freq = 48000;
diff --git a/src/codecs/music_wavpack.c b/src/codecs/music_wavpack.c
index 1163352c..fc9a1042 100644
--- a/src/codecs/music_wavpack.c
+++ b/src/codecs/music_wavpack.c
@@ -423,6 +423,7 @@ static void *WAVPACK_CreateFromIO_internal(SDL_IOStream *src1, SDL_IOStream *src
         break;
     }
 
+    SDL_zero(srcspec);
     srcspec.format = format;
     srcspec.channels = music->channels;
     srcspec.freq = (int)music->samplerate / DECIMATION(music);
diff --git a/src/codecs/music_xmp.c b/src/codecs/music_xmp.c
index f6e0dfc8..3aeaf9c2 100644
--- a/src/codecs/music_xmp.c
+++ b/src/codecs/music_xmp.c
@@ -260,6 +260,7 @@ void *XMP_CreateFromIO(SDL_IOStream *src, SDL_bool closeio)
     }
 
     music->volume = MIX_MAX_VOLUME;
+    SDL_zero(srcspec);
     srcspec.format = SDL_AUDIO_S16;
     srcspec.channels = 2;
     srcspec.freq = music_spec.freq;
diff --git a/src/mixer.c b/src/mixer.c
index 7dbfd270..f3d7042f 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -836,6 +836,7 @@ Mix_Chunk *Mix_LoadWAV_IO(SDL_IOStream *src, SDL_bool closeio)
     SDL_SeekIO(src, -4, SDL_IO_SEEK_CUR);
 
     /* First try loading via libsndfile */
+    SDL_zero(wavespec);
     loaded = Mix_LoadSndFile_IO(src, closeio, &wavespec, (Uint8 **)&chunk->abuf, &chunk->alen);
 
     if (!loaded)  {