[PATCH] psxhdrs/strncpy/stpncpy: Fix string turncation warning

Joel Sherrill joel at rtems.org
Wed Aug 5 12:19:54 UTC 2020


These are ok. This code is never executed.and these are reasonable changes.

On Wed, Aug 5, 2020, 6:54 AM Aschref Ben-Thabet <
aschref.ben-thabet at embedded-brains.de> wrote:

> From: Aschref Ben Thabet <aschref.ben-thabet at embedded-brains.de>
>
> Since we need to test the strncpy function, using a character array with
> a fixed array size in this case in place of character pointer can avoid
> the string turncation warning.
> ---
>  testsuites/psxtests/psxhdrs/string/stpncpy.c | 7 +++----
>  testsuites/psxtests/psxhdrs/string/strncpy.c | 7 +++----
>  2 files changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/testsuites/psxtests/psxhdrs/string/stpncpy.c
> b/testsuites/psxtests/psxhdrs/string/stpncpy.c
> index f81752de76..f7433a136f 100644
> --- a/testsuites/psxtests/psxhdrs/string/stpncpy.c
> +++ b/testsuites/psxtests/psxhdrs/string/stpncpy.c
> @@ -40,12 +40,11 @@
>
>   int test( void )
>   {
> -   char *dest = "Hello world";
> -   char *src = "Dude";
> -   size_t num = 2;
> +   char src[] = "Dude";
> +   char dest[ sizeof( src ) ];
>     char *result;
>
> -   result = stpncpy( dest, src, num );
> +   result = stpncpy( dest, src, sizeof( dest ) );
>
>     return ( result != NULL );
>   }
> diff --git a/testsuites/psxtests/psxhdrs/string/strncpy.c
> b/testsuites/psxtests/psxhdrs/string/strncpy.c
> index 50b64b3d57..e80d6f6e64 100644
> --- a/testsuites/psxtests/psxhdrs/string/strncpy.c
> +++ b/testsuites/psxtests/psxhdrs/string/strncpy.c
> @@ -35,16 +35,15 @@
>   #endif
>
>   #include <string.h>
> -
>   int test( void );
>
>   int test( void )
>   {
> -   char *dest = "Hello";
> -   char *src = "World";
> +   char src[] = "World";
> +   char dest[ sizeof( src ) ];
>     char *result;
>
> -   result = strncpy( dest, src, 3 );
> +   result = strncpy( dest, src, sizeof( dest ) );
>
>     return ( result != NULL );
>   }
> --
> 2.26.2
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20200805/3c76e144/attachment.html>


More information about the devel mailing list