On Mon, 20 Oct 2014, Vittorio Giovara wrote:

From: Luca Barbato <[email protected]>

Add error checking while at it.

CC: [email protected]
Bug-Id: CID 1135748
Signed-off-by: Vittorio Giovara <[email protected]>
---
libavformat/hdsenc.c             | 11 ++++++-----
libavformat/smoothstreamingenc.c |  7 ++++---
2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/libavformat/hdsenc.c b/libavformat/hdsenc.c
index 53fef33..316f3ff 100644
--- a/libavformat/hdsenc.c
+++ b/libavformat/hdsenc.c
@@ -31,6 +31,7 @@

#include "libavutil/avstring.h"
#include "libavutil/base64.h"
+#include "libavutil/file.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
@@ -204,8 +205,7 @@ static int write_manifest(AVFormatContext *s, int final)
    avio_printf(out, "</manifest>\n");
    avio_flush(out);
    avio_close(out);
-    rename(temp_filename, filename);
-    return 0;
+    return av_rename(temp_filename, filename);
}

static void update_size(AVIOContext *out, int64_t pos)
@@ -286,8 +286,7 @@ static int write_abst(AVFormatContext *s, OutputStream *os, 
int final)
    update_size(out, afrt_pos);
    update_size(out, 0);
    avio_close(out);
-    rename(temp_filename, filename);
-    return 0;
+    return av_rename(temp_filename, filename);
}

static int init_file(AVFormatContext *s, OutputStream *os, int64_t start_ts)
@@ -481,7 +480,9 @@ static int hds_flush(AVFormatContext *s, OutputStream *os, 
int final,

    snprintf(target_filename, sizeof(target_filename),
             "%s/stream%dSeg1-Frag%d", s->filename, index, os->fragment_index);
-    rename(os->temp_filename, target_filename);
+    ret = av_rename(os->temp_filename, target_filename);
+    if (ret < 0)
+        return ret;
    add_fragment(os, target_filename, os->frag_start_ts, end_ts - 
os->frag_start_ts);

    if (!final) {
diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index a6d0a36..c5d1c87 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -34,6 +34,7 @@

#include "libavutil/opt.h"
#include "libavutil/avstring.h"
+#include "libavutil/file.h"
#include "libavutil/mathematics.h"
#include "libavutil/intreadwrite.h"

@@ -282,8 +283,7 @@ static int write_manifest(AVFormatContext *s, int final)
    avio_printf(out, "</SmoothStreamingMedia>\n");
    avio_flush(out);
    avio_close(out);
-    rename(temp_filename, filename);
-    return 0;
+    return av_rename(temp_filename, filename);
}

static int ism_write_header(AVFormatContext *s)
@@ -540,7 +540,8 @@ static int ism_flush(AVFormatContext *s, int final)
        snprintf(header_filename, sizeof(header_filename), 
"%s/FragmentInfo(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
        snprintf(target_filename, sizeof(target_filename), 
"%s/Fragments(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
        copy_moof(s, filename, header_filename, moof_size);
-        rename(filename, target_filename);
+        if (ret = av_rename(filename, target_filename) < 0)
+            break;

Please read up on the operator precedence rules, this doesn't do what you mean (there's a reason these mostly use a separate pair of parentheses).

With the operator precedence fixed, I'm ok with the patch.

// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to