Fix some bugs with trying to access uninitialized variables.

This commit is contained in:
David Reid
2020-11-28 08:00:31 +10:00
parent d6864c5ab5
commit e7940394b2
2 changed files with 29 additions and 2 deletions
+12
View File
@@ -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;
}