[PATCH] avoid GCC 10 warning -Wstringop-truncation

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Jul 30 15:44:53 UTC 2020


On 30/07/2020 13:36, Aschref Ben-Thabet wrote:

> diff --git a/testsuites/psxtests/psxndbm01/init.c b/testsuites/psxtests/psxndbm01/init.c
> index a13afa7315..b524aff0df 100644
> --- a/testsuites/psxtests/psxndbm01/init.c
> +++ b/testsuites/psxtests/psxndbm01/init.c
> @@ -218,7 +218,7 @@ rtems_task Init(rtems_task_argument ignored)
>   
>     puts( "Fetch non-existing record and confirm error." );
>     test_strings = (char*)malloc(6);
> -  strncpy( test_strings, "Hello", 5 );
> +  memcpy( test_strings, "Hello", 5 );
>   
>     test_strings[5] = '\0';

In the glibc devel list this approach was suggested for problems like this:

*(char *) mempcpy( test_strings, "Hello", 5 ) = '\0';

https://sourceware.org/legacy-ml/libc-alpha/2000-08/msg00061.html



More information about the devel mailing list