[rtems commit] libblock: Fix string truncation warning

Sebastian Huber sebh at rtems.org
Sat Oct 10 13:16:00 UTC 2020


Module:    rtems
Branch:    master
Commit:    bc7ac71f8aaaff0c73469246c526741ec5b181ed
Changeset: http://git.rtems.org/rtems/commit/?id=bc7ac71f8aaaff0c73469246c526741ec5b181ed

Author:    Frank Kühndel <frank.kuehndel at embedded-brains.de>
Date:      Mon Oct  5 16:37:23 2020 +0200

libblock: Fix string truncation warning

This patch does not only fix the compiler warning below. memcpy() is the
better function at this place as the terminating NUL character is never
copied here. Instead more characters will be appended to the
'logical_disk_name' later on.

../../../cpukit/libblock/src/bdpart-register.c:41:5:
warning: 'strncpy' output truncated before terminating nul copying
as many bytes from a string as its length [-Wstringop-truncation]

---

 cpukit/libblock/src/bdpart-register.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpukit/libblock/src/bdpart-register.c b/cpukit/libblock/src/bdpart-register.c
index 9956e61..8a1de61 100644
--- a/cpukit/libblock/src/bdpart-register.c
+++ b/cpukit/libblock/src/bdpart-register.c
@@ -38,7 +38,7 @@ static char *create_logical_disk_name( const char *disk_name, char **marker)
   char *logical_disk_name = malloc( disk_name_size + RTEMS_BDPART_NUMBER_SIZE);
 
   if (logical_disk_name != NULL) {
-    strncpy( logical_disk_name, disk_name, disk_name_size);
+    memcpy( logical_disk_name, disk_name, disk_name_size);
     *marker = logical_disk_name + disk_name_size;
   }
 



More information about the vc mailing list