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

[C][Sema] -Wformat misleading idempotent FixItHint for scanning into const #133257

Open
whisperity opened this issue Mar 27, 2025 · 0 comments
Open
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@whisperity
Copy link
Member

The following code:

#include <stdio.h>
#include <stdlib.h>

void parse(char* in) {
    const char* B = (char*) malloc(42);
    sscanf(in, "%s", B);
}
<source>:7:23: warning: format specifies type 'char *' but the argument has type 'const char *' [-Wformat]
    7 |     sscanf(pos, "%s", B);
      |                  ~~   ^
      |                  %s

https://godbolt.org/z/Gnqvq4Kvd

produces a -Wformat warning that has a FixItHint attached, which does not actually change anything related to the code. Such a warning is a problem in interactive editors where the editor shows "fix available", and after applying the fix, the warning is still there.

Image

@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 Mar 27, 2025
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

No branches or pull requests

3 participants