[rtems commit] fsdosfsname01: Fix string truncation warning
Sebastian Huber
sebh at rtems.org
Thu Oct 15 17:23:00 UTC 2020
Module: rtems
Branch: master
Commit: 0a761a58c9097a0de04baf970f260594618090e8
Changeset: http://git.rtems.org/rtems/commit/?id=0a761a58c9097a0de04baf970f260594618090e8
Author: Frank Kühndel <frank.kuehndel at embedded-brains.de>
Date: Mon Oct 12 16:41:51 2020 +0200
fsdosfsname01: Fix string truncation warning
This patch fixes a compiler warning:
../../../testsuites/fstests/fsdosfsname01/init.c:430:19: warning:
'%s' directive output may be truncated writing up to 6424 bytes into
a region of size 257 [-Wformat-truncation=]
The buffer 'dirname' is exactly large enough so that no truncation
can ever occur. Using the return value of snprintf() is an official
supported way to suppress the warning.
I considered the comment of Joel Sherrill about not replacing snprintf():
https://lists.rtems.org/pipermail/devel/2020-September/062113.html
---
testsuites/fstests/fsdosfsname01/init.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/testsuites/fstests/fsdosfsname01/init.c b/testsuites/fstests/fsdosfsname01/init.c
index 3689da8..a916e39 100644
--- a/testsuites/fstests/fsdosfsname01/init.c
+++ b/testsuites/fstests/fsdosfsname01/init.c
@@ -422,14 +422,15 @@ static void test_creating_invalid_directories( void )
unsigned int index;
int rc;
char dirname[MAX_NAME_LENGTH_INVALID + MOUNT_DIR_SIZE + 1];
-
+ int len;
for ( index = 0; index < NUMBER_OF_DIRECTORIES_INVALID; ++index ) {
- snprintf( dirname,
- sizeof( dirname ),
- "%s/%s",
- MOUNT_DIR,
- DIRECTORY_NAMES_INVALID[index] );
+ len = snprintf( dirname,
+ sizeof( dirname ),
+ "%s/%s",
+ MOUNT_DIR,
+ DIRECTORY_NAMES_INVALID[index] );
+ rtems_test_assert( len < sizeof( dirname ) );
rc = mkdir( dirname, S_IRWXU | S_IRWXG | S_IRWXO );
rtems_test_assert( rc == -1 );
}
More information about the vc
mailing list