diff options
author | Frank Kühndel <frank.kuehndel@embedded-brains.de> | 2020-10-05 16:23:01 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2020-10-12 08:43:32 +0200 |
commit | 4763ef8d9b3d80599b8ac9f1f4a4c613f087c0e0 (patch) | |
tree | d4ae9aab5317c372b53f7639b5fe6982b6f0dc4f /testsuites/psxtests/psxndbm01/init.c | |
parent | libblock: Fix sparse disk (diff) | |
download | rtems-4763ef8d9b3d80599b8ac9f1f4a4c613f087c0e0.tar.bz2 |
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)
Diffstat (limited to '')
-rw-r--r-- | testsuites/psxtests/psxndbm01/init.c | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/testsuites/psxtests/psxndbm01/init.c b/testsuites/psxtests/psxndbm01/init.c index a13afa7315..cc95684622 100644 --- a/testsuites/psxtests/psxndbm01/init.c +++ b/testsuites/psxtests/psxndbm01/init.c @@ -89,6 +89,7 @@ rtems_task Init(rtems_task_argument ignored) int i; char *test_strings; + char hello_string[] = "hello"; DBM *db; @@ -217,14 +218,9 @@ rtems_task Init(rtems_task_argument ignored) 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); - strncpy( test_strings, "Hello", 5 ); - - test_strings[5] = '\0'; - /* The data pointed by test_string is now pointed by key.dptr */ - key.dptr = test_strings; - key.dsize = sizeof( test_strings ); + key.dptr = hello_string; + key.dsize = strlen( hello_string ) + 1; get_phone_no = dbm_fetch( db, key ); rtems_test_assert( get_phone_no.dptr == NULL ); dbm_close( db ); @@ -239,7 +235,6 @@ rtems_task Init(rtems_task_argument ignored) 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); puts( "Delete existing record and " |