sad

simple audio daemon
git clone git://git.2f30.org/sad
Log | Files | Refs | LICENSE

commit 51e02cc8887b9bcc6028ebeb27b035fa3d65e625
parent 6673e4b30b2ec0720d7ebf7e0028f22c2f320362
Author: sin <sin@2f30.org>
Date:   Thu, 25 Dec 2014 17:25:03 +0000

More error checking

Diffstat:
Msndio.c | 17++++++++---------
Mwav.c | 19+++++++++++++++----
2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/sndio.c b/sndio.c @@ -45,29 +45,28 @@ sndioopen(int bits, int rate, int channels) if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par)) { warnx("sio_{set,get}par: failed"); - sio_close(hdl); - hdl = NULL; - return -1; + goto err0; } if (par.bits != bits || par.rate != rate || par.pchan != channels || par.le != SIO_LE_NATIVE || par.sig != 1) { warnx("unsupported audio params"); - sio_close(hdl); - hdl = NULL; - return -1; + goto err0; } if (!sio_start(hdl)) { warnx("sio_start: failed"); - sio_close(hdl); - hdl = NULL; - return -1; + goto err0; } puts("Opened sndio output"); return 0; + +err0: + sio_close(hdl); + hdl = NULL; + return -1; } static void diff --git a/wav.c b/wav.c @@ -26,6 +26,12 @@ wavopen(const char *name) return -1; } + if (sfinfo.channels < 1 || sfinfo.channels > 2) { + warnx("sfinfo: unsupported number of channels %d", + sfinfo.channels); + goto err0; + } + switch (sfinfo.format & 0xff) { case SF_FORMAT_PCM_S8: bits = 8; @@ -41,12 +47,17 @@ wavopen(const char *name) break; default: warnx("sfinfo: unsupported format"); - sf_close(sf); - sf = NULL; - return -1; + goto err0; } - return output->open(16, sfinfo.samplerate, sfinfo.channels); + if (output->open(16, sfinfo.samplerate, sfinfo.channels) < 0) + goto err0; + + return 0; +err0: + sf_close(sf); + sf = NULL; + return -1; } static int