[PATCH 1/5] fsdosfsname01: Fix string truncation warning
Frank Kuehndel
frank.kuehndel at embedded-brains.de
Tue Oct 13 13:48:55 UTC 2020
From: Frank Kühndel <frank.kuehndel at embedded-brains.de>
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 3689da8eed..a916e392f7 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 );
}
--
2.26.2
More information about the devel
mailing list