From 4e8fc8f9919a427ac776d9b665068d62fc4645e1 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Fri, 2 Nov 2018 18:42:15 +0200 Subject: fix error handling in poll functions --- src/pcm.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pcm.c b/src/pcm.c index 7b96135..abf94ab 100644 --- a/src/pcm.c +++ b/src/pcm.c @@ -289,8 +289,10 @@ snd_pcm_poll_descriptors_count(snd_pcm_t *pcm) int snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space) { - if (space > (unsigned int)sio_nfds(pcm->hdl)) + if (space < (unsigned int)sio_nfds(pcm->hdl)) { + WARNX("not enough space: %u < %d", space, sio_nfds(pcm->hdl)); return -1; + } return sio_pollfd(pcm->hdl, pfds, (pcm->hw.stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN)); } @@ -298,10 +300,13 @@ snd_pcm_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space int snd_pcm_poll_descriptors_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents) { - if (!revents || nfds > (unsigned int)sio_nfds(pcm->hdl)) + if (nfds < (unsigned int)sio_nfds(pcm->hdl)) { + WARNX("not enough space: %u < %d", nfds, sio_nfds(pcm->hdl)); return -1; + } - *revents = sio_revents(pcm->hdl, pfds); + const int ret = sio_revents(pcm->hdl, pfds); + if (revents) *revents = ret; return 0; } -- cgit v1.2.3