[PATCH] Psxtest : Fix String Turncation warning
Sebastian Huber
sebastian.huber at embedded-brains.de
Wed Aug 12 14:47:29 UTC 2020
Hello Aschref,
On 12/08/2020 14:06, Aschref Ben-Thabet wrote:
> From: Aschref Ben Thabet<aschref.ben-thabet at embedded-brains.de>
>
> replace strncpy with memcpy to silence this warning and free the
> allocated memory block.
> ---
> testsuites/psxtests/psxndbm01/init.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/testsuites/psxtests/psxndbm01/init.c b/testsuites/psxtests/psxndbm01/init.c
> index b524aff0df..658af58df3 100644
> --- a/testsuites/psxtests/psxndbm01/init.c
> +++ b/testsuites/psxtests/psxndbm01/init.c
> @@ -216,11 +216,12 @@ 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." );
> + puts( "Fetch non-existing record and confirm error." );
please review your patches before you send them to the mailing list. You
should avoid unnecessary white space changes.
> test_strings = (char*)malloc(6);
> memcpy( test_strings, "Hello", 5 );
>
> test_strings[5] = '\0';
> + free(test_strings);
>
> /* The data pointed by test_string is now pointed by key.dptr */
> key.dptr = test_strings;
This free() makes no sense. The next code line uses the freed string.
Also the patch probably is not against the master.
Please review this code area if the use of dynamic memory for the string
is necessary. If yes, then use strdup(). Check if the memory is freed
after use.
More information about the devel
mailing list