Skip to content

[clang-tidy] Generates invalid code - adds invalid escapes to string literals #9683

Description

@Zingam

Environment

  • OS and version: Ubuntu 22.04
  • VS Code: 1.69.2
  • C/C++ extension: 1.11.4
  • OS and version of remote machine (if applicable):

I filed this bug agains Clang-Tidy here
llvm/llvm-project#56669

As Sean McManus (@sean-mcmanus) suggested that it maybe a VScode extension bug I'm filing it again. #9322 (comment)

Bug Summary and Steps to Reproduce

Bug Summary:

https://user-images.githubusercontent.com/47526411/180406454-7ad4fedd-813a-447b-bcb6-e8f95834c04e.png

The following was automatically fixed by Clang-Tidy and reformatted with clang-format:

void Config::CheckModified() {
    struct stat fileinfo;
    time_t mytime;
    char Buf[MAX_FILENAME];

    if (stat(szConfigName, &fileinfo) == -1) {
        fprintf(stderr, "CheckModified() Error: Cannot stat [%s]!\n", szConfigName);
        return;
    } else {
        mytime = fileinfo.st_mtime;
        if (mytime > m_LastModifiedTime) {
            snprintf(Buf, MAX_FILENAME, "%s", szConfigName);
            // BugID 7073: Suppressing output to stderr, it seems to be bothering dave.
            // fprintf(stderr, "CheckModified() Reloading Configuration [%s]\n", Buf);
            ResetState();
            LoadConfig(Buf);
        }
    }
}

Invalid output:

void Config::CheckModified() {
    struct stat fileinfo;
    time_t mytime = 0;
    char Buf[MAX_FILENAME];

    if (stat(szConfigName, &fileinfo) == -1) {
        fprintf(stderr, "CheckModified() Error: Cannot stat [%s]!\n", szConfigName);
        return;
    }
    mytime = fileinfo.st_mtime;
    if (mytime > m_LastModifiedTime) {
            snprintf(Buf, MAX_FILENAME, \"%s\", szConfigName);
            // BugID 7073: Suppressing output to stderr, it seems to be bothering dave.
            // fprintf(stderr, \"CheckModified() Reloading Configuration [%s]\
\", Buf);
            ResetState();
            LoadConfig(Buf);
    }
}

Steps to reproduce:

  1. In this environment...
  2. With this config...
  3. Do '...'
  4. See error...

Other Extensions

No response

Additional Information

No response

Metadata

Metadata

Labels

Feature: Code AnalysisRelated to integration with clang-tidy, cppcheck, cl.exe /analyze, etc.Language ServicebugfixedCheck the Milestone for the release in which the fix is or will be available.quick fixverifiedBug has been reproduced

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions