[PATCH 2/2] Psxtest : Fix String Turncation warning

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Aug 12 15:18:55 UTC 2020


Please use

git format-patch -v2

to generate a second version of the patch. This [PATCH 2/2] is 
confusing, for example where is [PATCH 1/2]?

On 12/08/2020 17:10, Aschref Ben-Thabet wrote:

> From: Aschref Ben Thabet<aschref.ben-thabet at embedded-brains.de>
>
> replace strncpy with strdup to silence this warning since it tries to
> allocate enough memory to hold the old string (plus a '\0' character
> to mark the end of the string).
> ---
>   testsuites/psxtests/psxndbm01/init.c | 7 ++-----
>   1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/testsuites/psxtests/psxndbm01/init.c b/testsuites/psxtests/psxndbm01/init.c
> index b524aff0df..d862f1d7f3 100644
> --- a/testsuites/psxtests/psxndbm01/init.c
> +++ b/testsuites/psxtests/psxndbm01/init.c
> @@ -216,11 +216,8 @@ rtems_task Init(rtems_task_argument ignored)
>     get_phone_no = dbm_fetch( db, name2 );
>     rtems_test_assert( strcmp( (const char*)get_phone_no.dptr, PHONE_NO2 ) == 0 );
>   
> -  puts( "Fetch non-existing record and confirm error." );
> -  test_strings = (char*)malloc(6);
> -  memcpy( test_strings, "Hello", 5 );
> -
> -  test_strings[5] = '\0';
> +  puts( "Fetch non-existing record and confirm error." );

Sorry, for being pedantic, but please check your patches against 
unnecessary white space changes.

In general, do not add white space at the end of lines.

> +  test_strings = strdup( "Hello");
There is a missing space before the closing ).


More information about the devel mailing list