From e7940394b26e7485d12cd3b3afedae2c826c09d4 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 28 Nov 2020 08:00:31 +1000 Subject: [PATCH] Fix some bugs with trying to access uninitialized variables. --- miniaudio.h | 19 +++++++++++++++++-- research/miniaudio_engine.h | 12 ++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index 4f3af16a..44b48827 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -1,6 +1,6 @@ /* Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file. -miniaudio - v0.10.26 - 2020-11-24 +miniaudio - v0.10.27 - TBD David Reid - mackron@gmail.com @@ -1447,7 +1447,7 @@ extern "C" { #define MA_VERSION_MAJOR 0 #define MA_VERSION_MINOR 10 -#define MA_VERSION_REVISION 26 +#define MA_VERSION_REVISION 27 #define MA_VERSION_STRING MA_XSTRINGIFY(MA_VERSION_MAJOR) "." MA_XSTRINGIFY(MA_VERSION_MINOR) "." MA_XSTRINGIFY(MA_VERSION_REVISION) #if defined(_MSC_VER) && !defined(__clang__) @@ -42869,6 +42869,18 @@ MA_API ma_result ma_data_source_get_data_format(ma_data_source* pDataSource, ma_ ma_uint32 sampleRate; ma_data_source_callbacks* pCallbacks = (ma_data_source_callbacks*)pDataSource; + if (pFormat != NULL) { + *pFormat = ma_format_unknown; + } + + if (pChannels != NULL) { + *pChannels = 0; + } + + if (pSampleRate != NULL) { + *pSampleRate = 0; + } + if (pCallbacks == NULL || pCallbacks->onGetDataFormat == NULL) { return MA_INVALID_ARGS; } @@ -64249,6 +64261,9 @@ The following miscellaneous changes have also been made. /* REVISION HISTORY ================ +v0.10.27 - TBD + - Fix some bugs with trying to access uninitialized variables. + v0.10.26 - 2020-11-24 - WASAPI: Fix a bug where the exclusive mode format may not be retrieved correctly due to accessing freed memory. - Fix a bug with ma_waveform where glitching occurs after changing frequency. diff --git a/research/miniaudio_engine.h b/research/miniaudio_engine.h index 239d4dea..60b5753b 100644 --- a/research/miniaudio_engine.h +++ b/research/miniaudio_engine.h @@ -3621,11 +3621,15 @@ static ma_result ma_rb_data_source_init(ma_rb* pRB, ma_format format, ma_uint32 return MA_INVALID_ARGS; } + MA_ZERO_OBJECT(pDataSource); /* For safety. */ + pDataSource->ds.onRead = NULL; pDataSource->ds.onSeek = NULL; /* We can't really seek in a ring buffer - there's no notion of a beginning and an end in a ring buffer. */ pDataSource->ds.onMap = ma_rb_data_source__on_map; pDataSource->ds.onUnmap = ma_rb_data_source__on_unmap; pDataSource->ds.onGetDataFormat = ma_rb_data_source__on_get_format; + pDataSource->ds.onGetCursor = NULL; + pDataSource->ds.onGetLength = NULL; pDataSource->pRB = pRB; pDataSource->format = format; pDataSource->channels = channels; @@ -6149,6 +6153,14 @@ MA_API ma_result ma_resource_manager_data_stream_get_data_format(ma_resource_man /* We cannot be using the data source after it's been uninitialized. */ MA_ASSERT(pDataStream->result != MA_UNAVAILABLE); + if (pFormat != NULL) { + *pFormat = ma_format_unknown; + } + + if (pChannels != NULL) { + *pChannels = 0; + } + if (pDataStream == NULL) { return MA_INVALID_ARGS; }