Add some safety checks to data sources.

With this change, an error is now returned when the requested frame
count is zero. Two reasons for this:

  1) It usually means there's an error in the higher level logic if
     something is trying to read zero frames.

  2) When no frames are read, MA_AT_END should be returned. However, if
     the input frame count is also zero, it creates ambiguity as to
     whether or not the data source is truly at the end.
This commit is contained in:
David Reid
2021-07-18 10:35:34 +10:00
parent d7d8520c82
commit 7b65f3748a
3 changed files with 134 additions and 30 deletions
+12
View File
@@ -268,6 +268,14 @@ MA_API void ma_libopus_uninit(ma_libopus* pOpus, const ma_allocation_callbacks*
MA_API ma_result ma_libopus_read_pcm_frames(ma_libopus* pOpus, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead)
{
if (pFramesRead != NULL) {
*pFramesRead = 0;
}
if (frameCount == 0) {
return MA_INVALID_ARGS;
}
if (pOpus == NULL) {
return MA_INVALID_ARGS;
}
@@ -317,6 +325,10 @@ MA_API ma_result ma_libopus_read_pcm_frames(ma_libopus* pOpus, void* pFramesOut,
*pFramesRead = totalFramesRead;
}
if (result == MA_SUCCESS && totalFramesRead == 0) {
result = MA_AT_END;
}
return result;
}
#else