[PATCH v4] Psxtest : Fix String Turncation warning
Sebastian Huber
sebastian.huber at embedded-brains.de
Mon Aug 17 09:57:46 UTC 2020
On 13/08/2020 17:58, 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).
Could you please check if the use of the sizeof here makes sense:
puts( "Fetch non-existing record and confirm error." );
test_strings = strdup( "Hello" );
/* The data pointed by test_string is now pointed by key.dptr */
key.dptr = test_strings;
key.dsize = sizeof( test_strings );
get_phone_no = dbm_fetch( db, key );
rtems_test_assert( get_phone_no.dptr == NULL );
dbm_close( db );
/* We need the 'key' object, hence we cannot free 'test_strings' */
/* dbm_delete() */
puts( "\nTestcases for 'dbm_delete()'" );
db = dbm_open( DB_NAME, O_RDWR, S_IRWXU );
rtems_test_assert( db != NULL );
puts( "Delete non-existing record and confirm error." );
rtems_test_assert( dbm_delete( db, key ) != 0 );
free( test_strings );
rtems_test_assert( count_no_of_records( db ) == 2);
Why do we have to allocate the string? Can't we simply use a string
constant?
More information about the devel
mailing list