Skip to content

Fix #10469 FP returnTempReference with overloaded operator+=#3678

Merged
danmar merged 4 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_Fix10469
Jan 12, 2022
Merged

Fix #10469 FP returnTempReference with overloaded operator+=#3678
danmar merged 4 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_Fix10469

Conversation

@chrchr-github

Copy link
Copy Markdown
Collaborator

Function parameters const char* s vs. const char s[] were not handled consistently in Variable and ValueType. I'm not sure that this is the right fix.

Comment thread lib/symboldatabase.cpp
ValueType::MatchResult res = ValueType::matchParameter(call, funcVar->valueType());
ValueType vt;
auto pvt = funcVar->valueType();
if (pvt && funcVar->isArray()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this work when array is passed by reference(ie void f(const T (&array)[N]))? Maybe we should call matchParameter first and then if it doesn't match adjust the valuetype if funcVar->isArray()?

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.

It works in the sense that there is no FP if I change the test case accordingly. But ValueType can't store the dimension N anyway.

Comment thread lib/symboldatabase.cpp Outdated
{
ValueType::MatchResult res = ValueType::matchParameter(call, funcVar->valueType());
ValueType vt;
auto pvt = funcVar->valueType();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe do ValueType vt = *funcVar->valueType(); and then just modify it directly.

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.

We have to check for nullptr first, otherwise there is a crash when running the tests.

@pfultz2

pfultz2 commented Jan 10, 2022

Copy link
Copy Markdown
Contributor

There is a merge conflict.

@danmar
danmar merged commit 1b89c99 into cppcheck-opensource:main Jan 12, 2022
@chrchr-github

Copy link
Copy Markdown
Collaborator Author

Now that I look at it again, isArray() should also be true for std::array. I'll have to check if this can cause problems.

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