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

Clang flag -Wmissing-format-attribute doesn't catch missing attributes #60718

Open
jstengleingithub opened this issue Feb 13, 2023 · 0 comments · May be fixed by #70024
Open

Clang flag -Wmissing-format-attribute doesn't catch missing attributes #60718

jstengleingithub opened this issue Feb 13, 2023 · 0 comments · May be fixed by #70024
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@jstengleingithub
Copy link
Contributor

jstengleingithub commented Feb 13, 2023

GCC has a valuable flag -Wmissing-format-attribute which shows functions missing a format attribute. While Clang supports this flag, it currently doesn't do anything.
Code:

#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
void safe_snprintf(char *outstring, const size_t length, const char *format, ... /* args */);
void safe_snprintf(char *outstring, const size_t length, const char *format, ... /* args */)
{
    va_list args;
    va_start(args, format);
    if ((outstring != NULL) && (length > 0)) {
        vsnprintf(outstring, length, format, args);
        outstring[length - 1] = 0;
    }
    va_end(args);
}

GCC warning:

$ gcc -c -Wmissing-format-attribute test.c
test.c: In function 'safe_snprintf':
test.c:18:9: warning: function 'safe_snprintf' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
         vsnprintf(outstring, length, format, args);
         ^~~~~~~~~
$ gcc --version
gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1)

Clang supports the flag but finds no issue:

$ ./clang -Wmissing-format-attribute -c ../../test.c
(no warning)
$ ./clang --version
Clang version 17.0.0  6ac13a798adae9a40023200dcaa6ed2e9fd9033a)
@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed new issue labels Feb 13, 2023
@AaronBallman AaronBallman linked a pull request May 31, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants