Skip to content

Correctly interpret boolean literals in execute()#4251

Merged
orbitcowboy merged 2 commits intocppcheck-opensource:mainfrom
tau-dev:main
Jul 8, 2022
Merged

Correctly interpret boolean literals in execute()#4251
orbitcowboy merged 2 commits intocppcheck-opensource:mainfrom
tau-dev:main

Conversation

@tau-dev
Copy link
Copy Markdown
Contributor

@tau-dev tau-dev commented Jul 7, 2022

This fixes some false positives, e.g. in the following code

void f(void) {
    char *c;
    char x;
    while (true) {
        c = &x;
        break;
    }
    ++c;
}

which originally resulted in

$ ./cppcheck --enable=warning x.c
Checking x.c ...
x.c:7:7: warning: Uninitialized variable: c [uninitvar]
    ++c;
      ^
x.c:3:12: note: Assuming condition is false
    while (true) {
           ^
x.c:7:7: note: Uninitialized variable: c
    ++c;
      ^

For some reason, I could not get the false positive to fire in a checkUninitVar testcase though.

@chrchr-github
Copy link
Copy Markdown
Collaborator

Thanks for your contribution.
The warning appears only in C mode, so you need to pass "test.c" as the file name.

valueFlowUninit("void f(void) {\n"
                "    char* c;\n"
                "    char x;\n"
                "    while (true) {\n"
                "        c = &x;\n"
                "        break;\n"
                "    }\n"
                "    ++c;\n"
                "}\n", "test.c");

@tau-dev
Copy link
Copy Markdown
Contributor Author

tau-dev commented Jul 7, 2022

That did the trick

@orbitcowboy orbitcowboy merged commit c17e2b9 into cppcheck-opensource:main Jul 8, 2022
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

Successfully merging this pull request may close these issues.

3 participants