Skip to content

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

Open
@whisperity

Description

@whisperity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions