Skip to content

Unhandled output truncation errors when building on CentOS 8.1 #435

@lethuillierg

Description

@lethuillierg

Describe the bug
On CentOS 8.1, when cFS is being built with enabled unit tests, make returns the following unhandled output truncation errors (-Werror=format-truncation=) related to osal unit tests:

[cfs@localhost cFS]$ make
make --no-print-directory -C "build" mission-all
[100%] Built target elf2cfetbl
[100%] Built target mission-version
[100%] Built target mission-prebuild
[  1%] Built target osal_posix_impl
[  2%] Built target osal_pc-linux_impl
[  3%] Built target osal_bsp
[  9%] Built target osal

[. . . omitting lines . . .]

[ 65%] Building C object osal/unit-tests/osfile-test/CMakeFiles/osal_file_UT.dir/ut_osfile_dirio_test.c.o
In file included from /home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.h:14,
                 from /home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:11:
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c: In function ‘UT_os_makedir_test’:
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:157:31: error: ‘%s’ directive output may be truncated writing up to 73 bytes into a region of size 30 [-Werror=format-truncation=]
     UT_os_sprintf(g_fileName, "%s/mkdir_File.txt", g_dirName);
                               ^~~~~~~~~~~~~~~~~~~  ~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:30: note: in definition of macro ‘UT_os_sprintf’
     snprintf(buf,sizeof(buf),__VA_ARGS__)
                              ^~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:5: note: ‘snprintf’ output between 16 and 89 bytes into a destination of size 30
     snprintf(buf,sizeof(buf),__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:157:5: note: in expansion of macro ‘UT_os_sprintf’
     UT_os_sprintf(g_fileName, "%s/mkdir_File.txt", g_dirName);
     ^~~~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c: In function ‘UT_os_readdir_test’:
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:465:37: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
     UT_os_sprintf(g_subdirNames[0], "%s/%s", g_dirName, g_tgtSubdirs[0]);
                                     ^~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:30: note: in definition of macro ‘UT_os_sprintf’
     snprintf(buf,sizeof(buf),__VA_ARGS__)
                              ^~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:5: note: ‘snprintf’ output 2 or more bytes (assuming 75) into a destination of size 74
     snprintf(buf,sizeof(buf),__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:465:5: note: in expansion of macro ‘UT_os_sprintf’
     UT_os_sprintf(g_subdirNames[0], "%s/%s", g_dirName, g_tgtSubdirs[0]);
     ^~~~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:475:37: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
     UT_os_sprintf(g_subdirNames[1], "%s/%s", g_dirName, g_tgtSubdirs[1]);
                                     ^~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:30: note: in definition of macro ‘UT_os_sprintf’
     snprintf(buf,sizeof(buf),__VA_ARGS__)
                              ^~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:5: note: ‘snprintf’ output 2 or more bytes (assuming 75) into a destination of size 74
     snprintf(buf,sizeof(buf),__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:475:5: note: in expansion of macro ‘UT_os_sprintf’
     UT_os_sprintf(g_subdirNames[1], "%s/%s", g_dirName, g_tgtSubdirs[1]);
     ^~~~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c: In function ‘UT_os_rewinddir_test’:
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:587:37: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
     UT_os_sprintf(g_subdirNames[0], "%s/%s", g_dirName, g_tgtSubdirs[0]);
                                     ^~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:30: note: in definition of macro ‘UT_os_sprintf’
     snprintf(buf,sizeof(buf),__VA_ARGS__)
                              ^~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:5: note: ‘snprintf’ output 2 or more bytes (assuming 75) into a destination of size 74
     snprintf(buf,sizeof(buf),__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:587:5: note: in expansion of macro ‘UT_os_sprintf’
     UT_os_sprintf(g_subdirNames[0], "%s/%s", g_dirName, g_tgtSubdirs[0]);
     ^~~~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:597:37: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
     UT_os_sprintf(g_subdirNames[1], "%s/%s", g_dirName, g_tgtSubdirs[1]);
                                     ^~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:30: note: in definition of macro ‘UT_os_sprintf’
     snprintf(buf,sizeof(buf),__VA_ARGS__)
                              ^~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:5: note: ‘snprintf’ output 2 or more bytes (assuming 75) into a destination of size 74
     snprintf(buf,sizeof(buf),__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:597:5: note: in expansion of macro ‘UT_os_sprintf’
     UT_os_sprintf(g_subdirNames[1], "%s/%s", g_dirName, g_tgtSubdirs[1]);
     ^~~~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c: In function ‘UT_os_removedir_test’:
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:755:31: error: ‘%s’ directive output may be truncated writing up to 73 bytes into a region of size 30 [-Werror=format-truncation=]
     UT_os_sprintf(g_fileName, "%s/rmdir_File1.txt", g_dirName);
                               ^~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:30: note: in definition of macro ‘UT_os_sprintf’
     snprintf(buf,sizeof(buf),__VA_ARGS__)
                              ^~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:5: note: ‘snprintf’ output between 17 and 90 bytes into a destination of size 30
     snprintf(buf,sizeof(buf),__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:755:5: note: in expansion of macro ‘UT_os_sprintf’
     UT_os_sprintf(g_fileName, "%s/rmdir_File1.txt", g_dirName);
     ^~~~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:774:31: error: ‘%s’ directive output may be truncated writing up to 73 bytes into a region of size 30 [-Werror=format-truncation=]
     UT_os_sprintf(g_fileName, "%s/rmdir_File2.txt", g_dirName);
                               ^~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:30: note: in definition of macro ‘UT_os_sprintf’
     snprintf(buf,sizeof(buf),__VA_ARGS__)
                              ^~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/inc/ut_os_support.h:82:5: note: ‘snprintf’ output between 17 and 90 bytes into a destination of size 30
     snprintf(buf,sizeof(buf),__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/cfs/cFS/osal/src/unit-tests/osfile-test/ut_osfile_dirio_test.c:774:5: note: in expansion of macro ‘UT_os_sprintf’
     UT_os_sprintf(g_fileName, "%s/rmdir_File2.txt", g_dirName);
     ^~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[7]: *** [osal/unit-tests/osfile-test/CMakeFiles/osal_file_UT.dir/build.make:76: osal/unit-tests/osfile-test/CMakeFiles/osal_file_UT.dir/ut_osfile_dirio_test.c.o] Error 1
make[6]: *** [CMakeFiles/Makefile2:5132: osal/unit-tests/osfile-test/CMakeFiles/osal_file_UT.dir/all] Error 2
make[5]: *** [Makefile:141: all] Error 2
make[4]: *** [CMakeFiles/native-all.dir/build.make:57: CMakeFiles/native-all] Error 2
make[3]: *** [CMakeFiles/Makefile2:325: CMakeFiles/native-all.dir/all] Error 2
make[2]: *** [CMakeFiles/Makefile2:139: CMakeFiles/mission-all.dir/rule] Error 2
make[1]: *** [Makefile:201: mission-all] Error 2
make: *** [Makefile:120: all] Error 2

To Reproduce
Steps to reproduce the behavior:

On an up-to-date CentOS 8.1, follow the current cFS README while enabling unit tests (step 7):

  1. git clone https://github.com/nasa/cFS.git
  2. cd cFS
  3. git submodule init
  4. git submodule update
  5. cp cfe/cmake/Makefile.sample Makefile
  6. cp -r cfe/cmake/sample_defs sample_defs
  7. make SIMULATION=native ENABLE_UNIT_TESTS=true prep
  8. make

Expected behavior
make should not return any error.

Code snips
N/A

System observed on:
 - iMac (Retina 4K, 2019)
 - OS: CentOS 8.1 (centos-release-8.1-1.1911.0.8.el8.x86_64) (via VMware Fusion 11.5.3) / minimal installation / packages installed: git, make, cmake, gcc.
 - GCC: 8.3.1 20190507 (Red Hat 8.3.1-4)
 - Versions: master bundle

Additional context
For convenience and mainly to investigate the possibility of performing automated end-to-end testing (for instance, to make a pseudo-GSW deterministically interact with the FSW and check the telemetry), I have taken the initiative to dockerize cFS.

In this context, these errors occurred when creating a CentOS-based Docker image. Their occurrence was then confirmed using a CentOS virtual machine (the logs provided above come from the unit tests performed on the virtual machine).

No such errors occur on (a virtualized) Ubuntu 18.04. This behavior seems then specific to CentOS, or perhaps to a certain version of GCC.

(Because these errors are directly related to osal, I have decided to open this issue here instead of the cFS repository).

Reporter Info
Guillaume Lethuillier
Personal

Metadata

Metadata

Assignees

Labels

build-systemunit-testTickets related to the OSAL unit testing (functional and/or coverage)

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions