diff mbox series

[FFmpeg-devel] cmdutils: replace strncpy() with direct assignment

Message ID 20210309174657.2336-1-anton@khirnov.net
State Accepted
Commit b334fd39c9c00c739faeece87fa81c980c148a16
Headers show
Series [FFmpeg-devel] cmdutils: replace strncpy() with direct assignment | expand

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

Anton Khirnov March 9, 2021, 5:46 p.m. UTC
Only one character is actually rewritten.

Fixes truncation warnings, such as
warning: ‘strncpy’ output truncated before terminating nul copying 3 bytes from a string of the same length [-Wstringop-truncation]
in gcc 10.2.0
---
 fftools/cmdutils.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Gregor Riepl March 9, 2021, 5:54 p.m. UTC | #1
>      // Change all the ' --' strings to '~--' so that
>      // they can be identified as tokens.
>      while ((conflist = strstr(str, " --")) != NULL) {
> -        strncpy(conflist, "~--", 3);
> +        conflist[0] = '~';
>      }

Doesn't this simply replace -- with ~- ?
The comment seems wrong to me...
Anton Khirnov March 11, 2021, 9:07 a.m. UTC | #2
Quoting Gregor Riepl (2021-03-09 18:54:11)
> >      // Change all the ' --' strings to '~--' so that
> >      // they can be identified as tokens.
> >      while ((conflist = strstr(str, " --")) != NULL) {
> > -        strncpy(conflist, "~--", 3);
> > +        conflist[0] = '~';
> >      }
> 
> Doesn't this simply replace -- with ~- ?
> The comment seems wrong to me...

No, it replaces ' --' with '~--', just as the comment says.
Anton Khirnov March 16, 2021, 9:46 a.m. UTC | #3
No further comments, so set pushed.
diff mbox series

Patch

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 8cfca22564..5a457b997b 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -1163,13 +1163,13 @@  static void print_buildconf(int flags, int level)
     // Change all the ' --' strings to '~--' so that
     // they can be identified as tokens.
     while ((conflist = strstr(str, " --")) != NULL) {
-        strncpy(conflist, "~--", 3);
+        conflist[0] = '~';
     }
 
     // Compensate for the weirdness this would cause
     // when passing 'pkg-config --static'.
     while ((remove_tilde = strstr(str, "pkg-config~")) != NULL) {
-        strncpy(remove_tilde, "pkg-config ", 11);
+        remove_tilde[sizeof("pkg-config~") - 2] = ' ';
     }
 
     splitconf = strtok(str, "~");