[PATCH] testsuites/fstests/dos: Fix format truncation warning

Aschref Ben-Thabet aschref.ben-thabet at embedded-brains.de
Tue Sep 15 09:05:27 UTC 2020


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

Replace the snprintf() code line with memcpy() and strcpy(). First copy
the MOUNT_DIR to dirname and add the '/' character, then copy the
invalide directory name.
---
 testsuites/fstests/fsdosfsname01/init.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/testsuites/fstests/fsdosfsname01/init.c b/testsuites/fstests/fsdosfsname01/init.c
index 3689da8eed..38ad8dd7c8 100644
--- a/testsuites/fstests/fsdosfsname01/init.c
+++ b/testsuites/fstests/fsdosfsname01/init.c
@@ -423,14 +423,11 @@ static void test_creating_invalid_directories( void )
   int          rc;
   char         dirname[MAX_NAME_LENGTH_INVALID + MOUNT_DIR_SIZE + 1];
 
-
   for ( index = 0; index < NUMBER_OF_DIRECTORIES_INVALID; ++index ) {
-    snprintf( dirname,
-              sizeof( dirname ),
-              "%s/%s",
-              MOUNT_DIR,
-              DIRECTORY_NAMES_INVALID[index] );
-    rc = mkdir( dirname, S_IRWXU | S_IRWXG | S_IRWXO );
+    memcpy( dirname, MOUNT_DIR, MOUNT_DIR_SIZE - 1);
+    dirname[MOUNT_DIR_SIZE - 1] = '/';
+    strcpy( dirname + MOUNT_DIR_SIZE, DIRECTORY_NAMES_INVALID[index]);
+    rc = mkdir(dirname, S_IRWXU | S_IRWXG | S_IRWXO);
     rtems_test_assert( rc == -1 );
   }
 }
-- 
2.26.2



More information about the devel mailing list