Skip to content

Fix #11599 false negative: constParameter - #4902

Merged
orbitcowboy merged 27 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_Fix11599
Apr 2, 2023
Merged

orbitcowboy merged 27 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_Fix11599

Conversation

@chrchr-github

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread lib/checkother.cpp Resolved
Comment thread test/testother.cpp Resolved
Comment thread lib/checkother.cpp Resolved
Comment thread lib/astutils.cpp Resolved
Comment thread test/testuninitvar.cpp Resolved
Comment thread lib/astutils.cpp Resolved
Comment thread lib/astutils.cpp Resolved
Comment thread test/testastutils.cpp
"void f(int* p) {\n"
" return g(&p);\n"
"}\n";
ASSERT_EQUALS(false, isVariableChangedByFunctionCall(code, "p ) ;", &inconclusive));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be true because the indirect will be set to 1, which will check that the data is modified and not the pointer.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If indirect is set to 0 then it should be false.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new formula and indirect always 0 (as it was before), this fails:

        code = "void g(int a[2]);\n"
               "void f() {\n"
               "    int b[2] = {};\n"
               "    return g(b);\n"
               "}\n";
        ASSERT_EQUALS(true, isVariableChangedByFunctionCall(code, "b ) ;", &inconclusive));
        ASSERT_EQUALS(true, inconclusive);

@pfultz2 pfultz2 Mar 23, 2023 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check for array and up the indirection since arrays are passed by pointer and not by value, I assume.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, a std::array can be passed by value, and since we like to conflate those...

@chrchr-github chrchr-github Mar 26, 2023 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconclusive was not reset (it is only ever set to true, never false.
So inconclusive is true if we haven't seen a declaration at all, but false if there is a possibly-changing declaration. Shouldn't the result also depend on the function's definition?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's one of the things I want to address with the work started in #4798.

@firewave

firewave commented Mar 30, 2023 •

Copy link
Copy Markdown
Collaborator

Needs to be rebased.

@chrchr-github

Copy link
Copy Markdown
Collaborator Author

Is this OK to be merged?

@orbitcowboy
orbitcowboy merged commit a336048 into cppcheck-opensource:main Apr 2, 2023
@chrchr-github
chrchr-github deleted the chr_Fix11599 branch May 22, 2023 19:02
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.

4 participants