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

Suppress format-truncation warnings #1097

Closed
skliper opened this issue Jan 14, 2021 · 4 comments · Fixed by #2078 or #2098
Closed

Suppress format-truncation warnings #1097

skliper opened this issue Jan 14, 2021 · 4 comments · Fixed by #2078 or #2098

Comments

@skliper
Copy link
Contributor

skliper commented Jan 14, 2021

Is your feature request related to a problem? Please describe.
It's only triggered when length limited *printf functions are used, and that's why we use them in the cFS context (to truncate as needed).

Describe the solution you'd like
Add -Wno-format-truncation to default flags, users can customize the flags as needed if they want to see these warnings.

Describe alternatives you've considered
Up to this point we've been implementing ways to suppress the individual warnings, but that just adds complexity where the point is to truncate when needed.

Additional context
None

Requester Info
Jacob Hageman - NASA/GSFC

@chillfig
Copy link
Contributor

@skliper Is it a reasonable approach if I added -Wno-format-truncation to the code below to achieve the desired truncation warning suppression?

add_compile_options(
-std=c99 # Target the C99 standard (without gcc extensions)
-pedantic # Issue all the warnings demanded by strict ISO C
-Wall # Warn about most questionable operations
-Wstrict-prototypes # Warn about missing prototypes
-Wwrite-strings # Warn if not treating string literals as "const"
-Wpointer-arith # Warn about suspicious pointer operations
-Wcast-align # Warn about casts that increase alignment requirements
-Werror # Treat warnings as errors (code should be clean)
)

This location make sense to me since

@jphickey
Copy link
Contributor

I can confirm that (because I'm using Ubuntu 21.10 which has GCC 11) that I have added these option to my local arch_build_custom.cmake file and CFE/OSAL builds fine after this.

I recommend adding both of these options, as they produce similar nuisance warnings:

 -Wno-format-truncation
 -Wno-stringop-truncation

One affects printf-style formatting, the other affects other string ops.

@jphickey
Copy link
Contributor

Main thing is to check/confirm that this option is benign to older GCC versions. I think we are still targeting/supporting CentOS7 which has gcc 4.8 (ancient history). So it would be wise to make sure this old compiler doesn't complain about that option.

@astrogeco
Copy link
Contributor

We should consider how many compilers we want to support and maybe draw a line just like we do with OSs and custom
configs

astrogeco added a commit that referenced this issue May 2, 2022
Fix #1097, adds truncation warning suppression flags
astrogeco added a commit that referenced this issue May 2, 2022
Fix #1097, adds truncation warning suppression flags
@skliper skliper added this to the Draco milestone Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants