Changeset 0a761a5 in rtems


Ignore:
Timestamp:
Oct 12, 2020, 2:41:51 PM (6 weeks ago)
Author:
Frank Kühndel <frank.kuehndel@…>
Branches:
master
Children:
2361b2c
Parents:
3972085
git-author:
Frank Kühndel <frank.kuehndel@…> (10/12/20 14:41:51)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/15/20 17:12:15)
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • testsuites/fstests/fsdosfsname01/init.c

    r3972085 r0a761a5  
    428428  int          rc;
    429429  char         dirname[MAX_NAME_LENGTH_INVALID + MOUNT_DIR_SIZE + 1];
    430 
     430  int          len;
    431431
    432432  for ( index = 0; index < NUMBER_OF_DIRECTORIES_INVALID; ++index ) {
    433     snprintf( dirname,
    434               sizeof( dirname ),
    435               "%s/%s",
    436               MOUNT_DIR,
    437               DIRECTORY_NAMES_INVALID[index] );
     433    len = snprintf( dirname,
     434                    sizeof( dirname ),
     435                    "%s/%s",
     436                    MOUNT_DIR,
     437                    DIRECTORY_NAMES_INVALID[index] );
     438    rtems_test_assert( len < sizeof( dirname ) );
    438439    rc = mkdir( dirname, S_IRWXU | S_IRWXG | S_IRWXO );
    439440    rtems_test_assert( rc == -1 );
Note: See TracChangeset for help on using the changeset viewer.