On 13/08/2020 17:58, Aschref Ben-Thabet wrote:

From: Aschref Ben Thabet<aschref.ben-tha...@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?

_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to