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 variadic *printf functions with __attribute__((format)). #79

Open
svkampen opened this issue May 16, 2020 · 2 comments
Open

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

svkampen opened this issue May 16, 2020 · 2 comments

Comments

@svkampen
Copy link

svkampen commented May 16, 2020

The format attribute marks a variadic function as taking a format string and corresponding arguments which should be type-checked against the format string. Marking printf_, sprintf_, etc. this way allows compilers to issue warnings when the supplied arguments do not have the correct type, as they would for the standard library functions.

The code change is very small, and currently implemented in svkampen@ba025a5 svkampen@d8aeaa9 (see comments below). I've guarded the __attribute__ declarations with #ifdef __GNUC__ ... #endif, so that they don't interfere with compilers that don't support them.

@joshklod
Copy link

joshklod commented Jul 2, 2020

The v*printf-style functions can also be marked using

format(<archetype>, <string-index>, 0)

to check the format string itself for errors. See the same link.

@svkampen
Copy link
Author

svkampen commented Jul 3, 2020

Thanks, I must have glossed over that while reading the documentation... I've updated my branch - svkampen@d8aeaa9 now contains the attributes for all of the functions.

eyalroz referenced this issue in eyalroz/printf Jun 30, 2021
* Fixes #79.
* Fixed a few more (GCC) warnings.
* Separated the warning-triggering cases into test cases of their own.
* Not using `signed size_t` - that's apparently not in the standard and not widely supported.
* Added a CMake option for whether or not to test the warning-triggering cases.
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

No branches or pull requests

2 participants