[FFmpeg-devel] [PATCH V3 2/5] libavformat/dashenc.c: fix build warning for [-Wformat-truncation=]
Guo, Yejun
yejun.guo at intel.com
Fri Feb 26 10:37:24 EET 2021
Part of warning message:
src/libavformat/dashenc.c: In function ‘flush_init_segment’:
src/libavformat/dashenc.c:608:49: warning: ‘%s’ directive output may be truncated writing up to 1023 bytes into a region of size between 1 and 1024 [-Wformat-truncation=]
snprintf(filename, sizeof(filename), "%s%s", c->dirname, os->initfile);
^~
src/libavformat/dashenc.c:608:9: note: ‘snprintf’ output between 1 and 2047 bytes into a destination of size 1024
snprintf(filename, sizeof(filename), "%s%s", c->dirname, os->initfile);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Guo, Yejun <yejun.guo at intel.com>
---
libavformat/dashenc.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 2d757b3a87..625be010be 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -126,7 +126,7 @@ typedef struct OutputStream {
char codec_str[100];
int written_len;
char filename[1024];
- char full_path[1024];
+ char full_path[2048];
char temp_path[1024];
double availability_time_offset;
AVProducerReferenceTime producer_reference_time;
@@ -604,9 +604,11 @@ static int flush_init_segment(AVFormatContext *s, OutputStream *os)
os->pos = os->init_range_length = range_length;
if (!c->single_file) {
- char filename[1024];
- snprintf(filename, sizeof(filename), "%s%s", c->dirname, os->initfile);
+ char *filename = av_asprintf("%s%s", c->dirname, os->initfile);
+ if (!filename)
+ return AVERROR(ENOMEM);
dashenc_io_close(s, &os->out, filename);
+ av_freep(&filename);
}
return 0;
}
@@ -1480,7 +1482,7 @@ static int dash_init(AVFormatContext *s)
AVFormatContext *ctx;
AVStream *st;
AVDictionary *opts = NULL;
- char filename[1024];
+ char *filename;
os->bit_rate = s->streams[i]->codecpar->bit_rate;
if (!os->bit_rate) {
@@ -1569,16 +1571,21 @@ static int dash_init(AVFormatContext *s)
} else {
ff_dash_fill_tmpl_params(os->initfile, sizeof(os->initfile), os->init_seg_name, i, 0, os->bit_rate, 0);
}
- snprintf(filename, sizeof(filename), "%s%s", c->dirname, os->initfile);
+ filename = av_asprintf("%s%s", c->dirname, os->initfile);
+ if (!filename)
+ return AVERROR(ENOMEM);
set_http_options(&opts, c);
if (!c->single_file) {
- if ((ret = avio_open_dyn_buf(&ctx->pb)) < 0)
+ if ((ret = avio_open_dyn_buf(&ctx->pb)) < 0) {
+ av_freep(&filename);
return ret;
+ }
ret = s->io_open(s, &os->out, filename, AVIO_FLAG_WRITE, &opts);
} else {
ctx->url = av_strdup(filename);
ret = avio_open2(&ctx->pb, filename, AVIO_FLAG_WRITE, NULL, &opts);
}
+ av_freep(&filename);
av_dict_free(&opts);
if (ret < 0)
return ret;
--
2.17.1
More information about the ffmpeg-devel
mailing list