Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled output truncation errors when building on CentOS 8.1 #435

Closed
lethuillierg opened this issue Apr 22, 2020 · 5 comments · Fixed by #441 or #458
Closed

Unhandled output truncation errors when building on CentOS 8.1 #435

lethuillierg opened this issue Apr 22, 2020 · 5 comments · Fixed by #441 or #458
Assignees
Labels
build-system unit-test Tickets related to the OSAL unit testing (functional and/or coverage)
Milestone

Comments

@lethuillierg
Copy link

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

@jphickey
Copy link
Contributor

GCC has been adding more and more validation/verification in recent releases, so these warnings are almost certainly related to the newer GCC version here.

Worth noting that @CDKnightNASA is actively working on putting these scattered string manipulations for error reporting into common code (e.g. nasa/cFE#492) which may either fix these or make them easier to fix once this effort is done.

@lethuillierg
Copy link
Author

Indeed: I have just installed GCC 8.4.0 (gcc (Ubuntu 8.4.0-1ubuntu1~18.04) 8.4.0) on Ubuntu and now the same errors occur.

@jphickey
Copy link
Contributor

Thanks for the confirmation... in the meantime you might try -Wno-format (IIRC) to avoid the warning as an interim workaround. You can add to sample_defs/global_build_options.cmake. Either that or remove -Werror. I'd rather not try to fix these until the other UT refactoring work is done, as it will likely be impossible to merge.

@lethuillierg
Copy link
Author

Thank you @jphickey.

At this time, I will directly install GCC 7 in my Docker images until cFS becomes fully compatible with GCC 8, but I keep your advice in mind.

I'd rather not try to fix these until the other UT refactoring work is done, as it will likely be impossible to merge.

I agree.

@jphickey
Copy link
Contributor

See related: nasa/cFE#641.

I'll also be rolling some fixes in for this with #285, as doing it separately would likely create a merge conflict.

@jphickey jphickey self-assigned this Apr 27, 2020
jphickey added a commit to jphickey/osal that referenced this issue Apr 29, 2020
Resize buffers and tweak string copies to avoid truncation warnings
in GCC 9.  Note the code was generally OK (handled truncation) but
the new compiler still generates warnings even with correct usage
of certain functions.

In the UT_os_printf macro, be sure to "use" the return value
of the snprintf() call, which avoids warnings about truncation.
jphickey added a commit to jphickey/osal that referenced this issue Apr 30, 2020
Resize buffers and tweak string copies to avoid truncation warnings
in GCC 9.  Note the code was generally OK (handled truncation) but
the new compiler still generates warnings even with correct usage
of certain functions.

In the UT_os_printf macro, be sure to "use" the return value
of the snprintf() call, which avoids warnings about truncation.
jphickey added a commit to jphickey/osal that referenced this issue May 5, 2020
Resize buffers and tweak string copies to avoid truncation warnings
in GCC 9.  Note the code was generally OK (handled truncation) but
the new compiler still generates warnings even with correct usage
of certain functions.

In the UT_os_printf macro, be sure to "use" the return value
of the snprintf() call, which avoids warnings about truncation.
jphickey added a commit to jphickey/osal that referenced this issue May 11, 2020
astrogeco added a commit that referenced this issue May 11, 2020
Fix #435, fix string manipulations to avoid warnings
@astrogeco astrogeco added bug unit-test Tickets related to the OSAL unit testing (functional and/or coverage) build-system and removed bug labels Sep 28, 2020
@skliper skliper added this to the v5.1.0 milestone Sep 24, 2021
jphickey added a commit to jphickey/osal that referenced this issue Aug 10, 2022
Use "UtTest_Setup" instead of "OS_Application_Startup"

This needs to be merged in coordination with a related change
in OSAL/UT Assert.  This also updates the UT application final
link to use "ut_assert" rather than "ut_bsp", as the separate
bsp for unit test is also getting phased out.
jphickey pushed a commit to jphickey/osal that referenced this issue Aug 10, 2022
Fix nasa#435: Update UT entry point
Resolve merge conflicts in fsw/cfe-core/unit-test/CMakeLists.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-system unit-test Tickets related to the OSAL unit testing (functional and/or coverage)
Projects
None yet
4 participants