Message ID | AM7PR03MB66603B15719A186A8A5B85FB8FA69@AM7PR03MB6660.eurprd03.prod.outlook.com |
---|---|
State | Accepted |
Headers | show |
Series | [FFmpeg-devel] avformat/argo_asf: Use memcpy to copy string without its NUL | expand |
Context | Check | Description |
---|---|---|
andriy/configurex86 | warning | Failed to apply patch |
andriy/configureppc | warning | Failed to apply patch |
On 26/9/21 1:09 pm, Andreas Rheinhardt wrote: > This avoids a -Wstringop-truncation warning from GCC which takes > issue with the fact that the destination might not be NUL terminated. > > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> > --- > libavformat/argo_asf.c | 20 +++++++------------- > 1 file changed, 7 insertions(+), 13 deletions(-) > > diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c > index 5adafb7230..0ef970df8a 100644 > --- a/libavformat/argo_asf.c > +++ b/libavformat/argo_asf.c > @@ -356,25 +356,19 @@ static int argo_asf_write_header(AVFormatContext *s) > .num_chunks = 1, > .chunk_offset = ASF_FILE_HEADER_SIZE > }; > + const char *name = ctx->name, *end; > + size_t len; > > /* > * If the user specified a name, use it as is. Otherwise take the > * basename and lop off the extension (if any). > */ > - if (ctx->name) { > - strncpy(fhdr.name, ctx->name, sizeof(fhdr.name)); > - } else { > - const char *start = av_basename(s->url); > - const char *end = strrchr(start, '.'); > - size_t len; > - > - if (end) > - len = end - start; > - else > - len = strlen(start); > + if (name || !(end = strrchr(name = av_basename(s->url), '.'))) { > + len = strlen(name); > + } else > + len = end - name; > > - memcpy(fhdr.name, start, FFMIN(len, sizeof(fhdr.name))); > - } > + memcpy(fhdr.name, name, FFMIN(len, sizeof(fhdr.name))); > Minor formatting nits: * The first statement has braces, the second doesn't. * A set of parentheses around "name = av_basename(s->url)" would make things clearer. Otherwise, lgtm. Zane
Zane van Iperen: > > > On 26/9/21 1:09 pm, Andreas Rheinhardt wrote: >> This avoids a -Wstringop-truncation warning from GCC which takes >> issue with the fact that the destination might not be NUL terminated. >> >> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> >> --- >> libavformat/argo_asf.c | 20 +++++++------------- >> 1 file changed, 7 insertions(+), 13 deletions(-) >> >> diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c >> index 5adafb7230..0ef970df8a 100644 >> --- a/libavformat/argo_asf.c >> +++ b/libavformat/argo_asf.c >> @@ -356,25 +356,19 @@ static int argo_asf_write_header(AVFormatContext >> *s) >> .num_chunks = 1, >> .chunk_offset = ASF_FILE_HEADER_SIZE >> }; >> + const char *name = ctx->name, *end; >> + size_t len; >> /* >> * If the user specified a name, use it as is. Otherwise take the >> * basename and lop off the extension (if any). >> */ >> - if (ctx->name) { >> - strncpy(fhdr.name, ctx->name, sizeof(fhdr.name)); >> - } else { >> - const char *start = av_basename(s->url); >> - const char *end = strrchr(start, '.'); >> - size_t len; >> - >> - if (end) >> - len = end - start; >> - else >> - len = strlen(start); >> + if (name || !(end = strrchr(name = av_basename(s->url), '.'))) { >> + len = strlen(name); >> + } else >> + len = end - name; >> - memcpy(fhdr.name, start, FFMIN(len, sizeof(fhdr.name))); >> - } >> + memcpy(fhdr.name, name, FFMIN(len, sizeof(fhdr.name))); >> > > Minor formatting nits: > * The first statement has braces, the second doesn't. > * A set of parentheses around "name = av_basename(s->url)" would make > things clearer. > > Otherwise, lgtm. > Applied with that changes. Thanks for the speedy review. - Andreas
diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c index 5adafb7230..0ef970df8a 100644 --- a/libavformat/argo_asf.c +++ b/libavformat/argo_asf.c @@ -356,25 +356,19 @@ static int argo_asf_write_header(AVFormatContext *s) .num_chunks = 1, .chunk_offset = ASF_FILE_HEADER_SIZE }; + const char *name = ctx->name, *end; + size_t len; /* * If the user specified a name, use it as is. Otherwise take the * basename and lop off the extension (if any). */ - if (ctx->name) { - strncpy(fhdr.name, ctx->name, sizeof(fhdr.name)); - } else { - const char *start = av_basename(s->url); - const char *end = strrchr(start, '.'); - size_t len; - - if (end) - len = end - start; - else - len = strlen(start); + if (name || !(end = strrchr(name = av_basename(s->url), '.'))) { + len = strlen(name); + } else + len = end - name; - memcpy(fhdr.name, start, FFMIN(len, sizeof(fhdr.name))); - } + memcpy(fhdr.name, name, FFMIN(len, sizeof(fhdr.name))); chdr.num_blocks = 0; chdr.num_samples = ASF_SAMPLE_COUNT;
This avoids a -Wstringop-truncation warning from GCC which takes issue with the fact that the destination might not be NUL terminated. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/argo_asf.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)