[FFmpeg-cvslog] lavc/libxvid: return meaningful error codes

Lukasz Marek git at videolan.org
Tue Nov 25 22:18:36 CET 2014


ffmpeg | branch: master | Lukasz Marek <lukasz.m.luki2 at gmail.com> | Mon Nov 24 01:11:45 2014 +0100| [2a89afb376aebe833bee0b5958cec16c48936b03] | committer: Lukasz Marek

lavc/libxvid: return meaningful error codes

Signed-off-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2a89afb376aebe833bee0b5958cec16c48936b03
---

 libavcodec/libxvid.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c
index 020af32..046d2f7 100644
--- a/libavcodec/libxvid.c
+++ b/libavcodec/libxvid.c
@@ -488,6 +488,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx)
         if (!x->twopassbuffer || !x->old_twopassbuffer) {
             av_log(avctx, AV_LOG_ERROR,
                    "Xvid: Cannot allocate 2-pass log buffers\n");
+            ret = AVERROR(ENOMEM);
             goto fail;
         }
         x->twopassbuffer[0]     =
@@ -501,8 +502,9 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx)
         rc2pass2.bitrate = avctx->bit_rate;
 
         fd = av_tempfile("xvidff.", &x->twopassfile, 0, avctx);
-        if (fd == -1) {
+        if (fd < 0) {
             av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot write 2-pass pipe\n");
+            ret = fd;
             goto fail;
         }
         x->twopassfd = fd;
@@ -510,14 +512,19 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx)
         if (!avctx->stats_in) {
             av_log(avctx, AV_LOG_ERROR,
                    "Xvid: No 2-pass information loaded for second pass\n");
+            ret = AVERROR(EINVAL);
             goto fail;
         }
 
-        if (strlen(avctx->stats_in) >
-            write(fd, avctx->stats_in, strlen(avctx->stats_in))) {
+        ret = write(fd, avctx->stats_in, strlen(avctx->stats_in));
+        if (ret == -1)
+            ret = AVERROR(errno);
+        else if (strlen(avctx->stats_in) > ret) {
             av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot write to 2-pass pipe\n");
-            goto fail;
+            ret = AVERROR(EIO);
         }
+        if (ret < 0)
+            goto fail;
 
         rc2pass2.filename                          = x->twopassfile;
         plugins[xvid_enc_create.num_plugins].func  = xvid_plugin_2pass2;



More information about the ffmpeg-cvslog mailing list