diff options
author | Chris Robinson <[email protected]> | 2022-11-07 06:11:08 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-11-07 06:11:08 -0800 |
commit | 0ec1a4a600f6460878ea2beb17ac57e5b22f35d5 (patch) | |
tree | ce6e4eca4890d8cdd8d13bb2b3d82e3af40d93c1 /alc | |
parent | a96d9c9c1d2170bdc6232fb76d3fb58f17b04e88 (diff) |
Make sure sio_write and sio_read return valid values
Diffstat (limited to 'alc')
-rw-r--r-- | alc/backends/sndio.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index 48387c65..077e77f2 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -22,13 +22,13 @@ #include "sndio.h" +#include <functional> +#include <inttypes.h> #include <poll.h> #include <stdio.h> #include <stdlib.h> #include <string.h> - #include <thread> -#include <functional> #include "alnumeric.h" #include "core/device.h" @@ -98,9 +98,9 @@ int SndioPlayback::mixerProc() while(!buffer.empty() && !mKillNow.load(std::memory_order_acquire)) { size_t wrote{sio_write(mSndHandle, buffer.data(), buffer.size())}; - if(wrote == 0) + if(wrote > buffer.size() || wrote == 0) { - ERR("sio_write failed\n"); + ERR("sio_write failed: 0x%" PRIx64 "\n", wrote); mDevice->handleDisconnect("Failed to write playback samples"); break; } @@ -353,7 +353,14 @@ int SndioCapture::recordProc() while(!buffer.empty()) { size_t got{sio_read(mSndHandle, buffer.data(), buffer.size())}; - if(got == 0) break; + if(got == 0) + break; + if(got > buffer.size()) + { + ERR("sio_read failed: 0x%" PRIx64 "\n", got); + mDevice->handleDisconnect("sio_read failed: 0x%" PRIx64, got); + break; + } mRing->writeAdvance(got / frameSize); buffer = buffer.subspan(got); |