diff mbox series

[FFmpeg-devel,V3,4/5] libavformat/smoothstreamingenc.c: fix build warning for [-Wformat-truncation=]

Message ID 20210226083727.2042-4-yejun.guo@intel.com
State New
Headers show
Series [FFmpeg-devel,V3,1/5] libavdevice/v4l2.c: fix build warning for [-Wformat-truncation=]
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Guo, Yejun Feb. 26, 2021, 8:37 a.m. UTC
Part of the build message:
src/libavformat/smoothstreamingenc.c: In function ‘ism_flush’:
src/libavformat/smoothstreamingenc.c:510:49: warning: ‘/temp’ directive output may be truncated writing 5 bytes into a region of size between 1 and 1024 [-Wformat-truncation=]
         snprintf(filename, sizeof(filename), "%s/temp", os->dirname);
                                                 ^~~~~
src/libavformat/smoothstreamingenc.c:510:9: note: ‘snprintf’ output between 6 and 1029 bytes into a destination of size 1024
         snprintf(filename, sizeof(filename), "%s/temp", os->dirname);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/libavformat/smoothstreamingenc.c:538:53: warning: ‘/temp’ directive output may be truncated writing 5 bytes into a region of size between 1 and 1024 [-Wformat-truncation=]
             snprintf(filename, sizeof(filename), "%s/temp", os->dirname);
                                                     ^~~~~
src/libavformat/smoothstreamingenc.c:538:13: note: ‘snprintf’ output between 6 and 1029 bytes into a destination of size 1024
             snprintf(filename, sizeof(filename), "%s/temp", os->dirname);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/libavformat/smoothstreamingenc.c:545:63: warning: ‘/FragmentInfo(’ directive output may be truncated writing 14 bytes into a region of size between 1 and 1024 [-Wformat-truncation=]
         snprintf(header_filename, sizeof(header_filename), "%s/FragmentInfo(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
                                                               ^~~~~~~~~~~~~~
src/libavformat/smoothstreamingenc.c:545:60: note: using the range [0, 18446744073709551615] for directive argument
         snprintf(header_filename, sizeof(header_filename), "%s/FragmentInfo(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
                                                            ^~~~~~~~~~~~~~~~~~~~~~
src/libavformat/smoothstreamingenc.c:545:9: note: ‘snprintf’ output 18 or more bytes (assuming 1041) into a destination of size 1024
         snprintf(header_filename, sizeof(header_filename), "%s/FragmentInfo(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
---
 libavformat/smoothstreamingenc.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index ba5cc27ca0..dc48bc7aa4 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -501,7 +501,8 @@  static int ism_flush(AVFormatContext *s, int final)
 
     for (i = 0; i < s->nb_streams; i++) {
         OutputStream *os = &c->streams[i];
-        char filename[1024], target_filename[1024], header_filename[1024], curr_dirname[1024];
+        char filename[sizeof(os->dirname) + 5], curr_dirname[1024];
+        char *target_filename, *header_filename;
         int64_t size;
         int64_t start_ts, duration, moof_size;
         if (!os->packets_written)
@@ -542,14 +543,24 @@  static int ism_flush(AVFormatContext *s, int final)
                 return ret;
         }
 
-        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);
+        header_filename = av_asprintf("%s/FragmentInfo(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
+        target_filename = av_asprintf("%s/Fragments(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
+        if (!header_filename || !target_filename) {
+            av_freep(&target_filename);
+            av_freep(&header_filename);
+            return AVERROR(ENOMEM);
+        }
         copy_moof(s, filename, header_filename, moof_size);
         ret = ff_rename(filename, target_filename, s);
-        if (ret < 0)
+        if (ret < 0) {
+            av_freep(&target_filename);
+            av_freep(&header_filename);
             break;
+        }
         add_fragment(os, target_filename, header_filename, start_ts, duration,
                      os->cur_start_pos, size);
+        av_freep(&target_filename);
+        av_freep(&header_filename);
     }
 
     if (c->window_size || (final && c->remove_at_exit)) {