[FFmpeg-devel] [PATCH] oss_audio: check all ioctl() return codes

Timothy Gu timothygu99 at gmail.com
Fri Jul 18 02:59:43 CEST 2014


Also uses a macro to simplify.

Signed-off-by: Timothy Gu <timothygu99 at gmail.com>
---

Found with clang's static analyzer.

---
 libavdevice/oss_audio.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/libavdevice/oss_audio.c b/libavdevice/oss_audio.c
index 734e565..3c5065c 100644
--- a/libavdevice/oss_audio.c
+++ b/libavdevice/oss_audio.c
@@ -87,8 +87,15 @@ static int audio_open(AVFormatContext *s1, int is_output, const char *audio_devi
 
     s->frame_size = AUDIO_BLOCK_SIZE;
 
+#define CHECK_IOCTL_ERROR(event)                                              \
+    if (err < 0) {                                                            \
+        av_log(s1, AV_LOG_ERROR, #event ": %s\n", strerror(errno));         \
+        goto fail;                                                            \
+    }
+
     /* select format : favour native format */
     err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp);
+    CHECK_IOCTL_ERROR(SNDCTL_DSP_GETFMTS)
 
 #if HAVE_BIGENDIAN
     if (tmp & AFMT_S16_BE) {
@@ -121,24 +128,15 @@ static int audio_open(AVFormatContext *s1, int is_output, const char *audio_devi
         return AVERROR(EIO);
     }
     err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp);
-    if (err < 0) {
-        av_log(s1, AV_LOG_ERROR, "SNDCTL_DSP_SETFMT: %s\n", strerror(errno));
-        goto fail;
-    }
+    CHECK_IOCTL_ERROR(SNDCTL_DSP_SETFMTS)
 
     tmp = (s->channels == 2);
     err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);
-    if (err < 0) {
-        av_log(s1, AV_LOG_ERROR, "SNDCTL_DSP_STEREO: %s\n", strerror(errno));
-        goto fail;
-    }
+    CHECK_IOCTL_ERROR(SNDCTL_DSP_STEREO)
 
     tmp = s->sample_rate;
     err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &tmp);
-    if (err < 0) {
-        av_log(s1, AV_LOG_ERROR, "SNDCTL_DSP_SPEED: %s\n", strerror(errno));
-        goto fail;
-    }
+    CHECK_IOCTL_ERROR(SNDCTL_DSP_SPEED)
     s->sample_rate = tmp; /* store real sample rate */
     s->fd = audio_fd;
 
@@ -146,6 +144,7 @@ static int audio_open(AVFormatContext *s1, int is_output, const char *audio_devi
  fail:
     close(audio_fd);
     return AVERROR(EIO);
+#undef CHECK_IOCTL_ERROR
 }
 
 static int audio_close(AudioData *s)
-- 
1.9.1



More information about the ffmpeg-devel mailing list