mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user