Changeset 4763ef8 in rtems


Ignore:
Timestamp:
Oct 5, 2020, 2:23:01 PM (7 weeks ago)
Author:
Frank Kühndel <frank.kuehndel@…>
Branches:
master
Children:
f3df25b
Parents:
b434dc1
git-author:
Frank Kühndel <frank.kuehndel@…> (10/05/20 14:23:01)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/12/20 06:43:32)
Message:

psxndbm01 - Fixing string truncation warning

This fixes the following compiler warning:

testsuites/psxtests/psxndbm01/init.c:221:3: warning: 'strncpy' output truncated
before terminating nul copying 5 bytes from a string of the same length

221 | strncpy( test_strings, "Hello", 5 );

|

In addition, the comments from Sebastian Huber on an old version of
such a patch have been taken into account:

1) The use of sizeof() in key.dsize = sizeof( test_strings ); is wrong.

2) There is no need to allocate the string. One can simply use a string

constant.

(See https://lists.rtems.org/pipermail/devel/2020-August/061418.html)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • testsuites/psxtests/psxndbm01/init.c

    rb434dc1 r4763ef8  
    9090  int i;
    9191  char *test_strings;
     92  char hello_string[] = "hello";
    9293
    9394  DBM *db;
     
    218219
    219220  puts( "Fetch non-existing record and confirm error." );
    220   test_strings = (char*)malloc(6);
    221   strncpy( test_strings, "Hello", 5 );
    222 
    223   test_strings[5] = '\0';
    224 
    225221/* The data pointed by test_string is now pointed by key.dptr */
    226   key.dptr = test_strings;
    227   key.dsize = sizeof( test_strings );
     222  key.dptr = hello_string;
     223  key.dsize = strlen( hello_string ) + 1;
    228224  get_phone_no = dbm_fetch( db, key );
    229225  rtems_test_assert( get_phone_no.dptr == NULL );
     
    240236  puts( "Delete non-existing record and confirm error." );
    241237  rtems_test_assert( dbm_delete( db, key ) != 0 );
    242   free( test_strings );
    243238  rtems_test_assert( count_no_of_records( db ) == 2);
    244239
Note: See TracChangeset for help on using the changeset viewer.