summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-11-02 18:42:15 +0200
committerJari Vetoniemi <mailroxas@gmail.com>2018-11-02 18:42:15 +0200
commit4e8fc8f9919a427ac776d9b665068d62fc4645e1 (patch)
treeb78afc743804f091c48c92966a31fde0d15c4f31
parent45a698438d119a0a0c019835765b51af624ce97e (diff)
fix error handling in poll functions
-rw-r--r--src/pcm.c11
1 files 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;
}