[PATCH] avoid GCC 10 warning -Wstringop-truncation

Aschref Ben-Thabet aschref.ben-thabet at embedded-brains.de
Thu Jul 30 11:36:12 UTC 2020


From: Aschref Ben Thabet <aschref.ben-thabet at embedded-brains.de>

GCC 10 warns about an overlapping using strncpy.
-> Replace some calls of strncpy with a memcpy to avoid this issue.
---
 cpukit/libblock/src/bdpart-mount.c   | 4 ++--
 testsuites/psxtests/psxndbm01/init.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/cpukit/libblock/src/bdpart-mount.c b/cpukit/libblock/src/bdpart-mount.c
index cfc08ead30..f689b18ebb 100644
--- a/cpukit/libblock/src/bdpart-mount.c
+++ b/cpukit/libblock/src/bdpart-mount.c
@@ -54,7 +54,7 @@ rtems_status_code rtems_bdpart_mount(
   if (logical_disk_name == NULL) {
     return RTEMS_NO_MEMORY;
   }
-  strncpy( logical_disk_name, disk_name, disk_name_size);
+  memcpy( logical_disk_name, disk_name, disk_name_size);
 
   /* Get disk file name */
   if (disk_file_name != NULL) {
@@ -148,7 +148,7 @@ rtems_status_code rtems_bdpart_unmount(
     esc = RTEMS_NO_MEMORY;
     goto cleanup;
   }
-  strncpy( mount_point, mount_base, mount_base_size);
+  memcpy( mount_point, mount_base, mount_base_size);
   mount_point [mount_base_size] = '/';
   strncpy( mount_point + mount_base_size + 1, disk_file_name, disk_file_name_size);
 
diff --git a/testsuites/psxtests/psxndbm01/init.c b/testsuites/psxtests/psxndbm01/init.c
index a13afa7315..b524aff0df 100644
--- a/testsuites/psxtests/psxndbm01/init.c
+++ b/testsuites/psxtests/psxndbm01/init.c
@@ -218,7 +218,7 @@ rtems_task Init(rtems_task_argument ignored)
 
   puts( "Fetch non-existing record and confirm error." );
   test_strings = (char*)malloc(6);
-  strncpy( test_strings, "Hello", 5 );
+  memcpy( test_strings, "Hello", 5 );
 
   test_strings[5] = '\0';
 
-- 
2.26.2



More information about the devel mailing list