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

Mark the *printf functions with __attribute__((format)). #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

svkampen
Copy link

See issue #79.

Using __attribute__((format)) means that compilers supporting the
attribute (GCC, clang, icc, perhaps others) will automatically issue
warnings when printf arguments are incorrectly typed (i.e. inconsistent
with the type specified in the format string).
@codecov-commenter
Copy link

codecov-commenter commented Jul 3, 2020

Codecov Report

Merging #80 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #80   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          359       359           
=========================================
  Hits           359       359           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d3b9846...d8aeaa9. Read the comment docs.

@svkampen svkampen changed the title Mark the variadic *printf functions with __attribute__((format)). Mark the *printf functions with __attribute__((format)). Jul 3, 2020
@eyalroz
Copy link

eyalroz commented Jun 29, 2021

When the format attribute is added, we get a massive amounts of warnings from test_suite.cpp, including:

warning: flag ' ' results in undefined behavior with 's' conversion specifier [-Wformat]
warning: format specifies type 'char' but the argument has type 'int' [-Wformat]
warning: invalid conversion specifier 'b' [-Wformat-invalid-specifier]
 warning: flag '#' results in undefined behavior with 'u' conversion specifier [-Wformat]

Some can just be fixed by explicit casting (and TBH it's a bit surprising that they work... are we saved by the ABI perhaps?) ; others cannot.

What are your thoughts?...

Naturally, this is not my repository, but I've been thinking of merging this into my fork, which already has, merged, the work of some others around here (e.g. warning fixes, glibc %p behavior etc.). I even created a PR for that, but while merging I noticed all those warnings.

@joshklod
Copy link

When the format attribute is added, we get a massive amounts of warnings from test_suite.cpp

I believe I fixed this in my fork. See joshklod:format-attr for my implementation of this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants