diff mbox series

[FFmpeg-devel] cmdutils: replace strncpy() with equivalent memcpy()

Message ID 20210308084511.12629-1-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel] cmdutils: replace strncpy() with equivalent memcpy()
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

Anton Khirnov March 8, 2021, 8:45 a.m. UTC
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

Andreas Rheinhardt March 8, 2021, 12:54 p.m. UTC | #1
Anton Khirnov:
> 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(-)
> 
> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
> index 8cfca22564..505006cd8b 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);
> +        memcpy(conflist, "~--", 3);
>      }
>  
>      // 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);
> +        memcpy(remove_tilde, "pkg-config ", 11);
>      }
>  
>      splitconf = strtok(str, "~");
> 
Wouldn't it be more natural to just use "conflist[0] = '~'" when
changing only one character?

- Andreas
diff mbox series

Patch

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 8cfca22564..505006cd8b 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);
+        memcpy(conflist, "~--", 3);
     }
 
     // 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);
+        memcpy(remove_tilde, "pkg-config ", 11);
     }
 
     splitconf = strtok(str, "~");