Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #11093, #12377 FP mismatchingContainerIterator #5911

Merged
merged 6 commits into from
Feb 9, 2024

Conversation

chrchr-github
Copy link
Collaborator

…r to get reference to container

@chrchr-github chrchr-github changed the title Fix #11093 FP: mismatchingContainerIterator caused by ternary operato… Fix #11093, #12377 FP mismatchingContainerIterator Jan 23, 2024
@@ -866,6 +879,8 @@ void CheckStl::mismatchingContainerIterator()
ValueFlow::Value val = getLifetimeIteratorValue(iterTok);
if (!val.tokvalue)
continue;
if (!val.isKnown() && Token::simpleMatch(val.tokvalue->astParent(), ":"))
Copy link
Contributor

Choose a reason for hiding this comment

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

The lifetime values are never known. Also, this will lead to FNs as well. I think it would be better to check that the set of lifetimes are the same when there are multiple lifetimes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Isn't the problem that there is only one value? Otherwise, getLifetimeIteratorValue() would return an empty value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yea, thats right, but it should be multiple values. I wonder why we are not getting both lifetime.

I assumed the error is that one variable has the lifetime v1 and the other has the lifetime v2. It should have both lifetimes.

lib/checkstl.cpp Outdated
for (std::size_t i = 0; i < address1.size(); ++i)
for (std::size_t j = 0; j < address2.size(); ++j)
if (isSameExpression(true, false, address1[i], address2[j], library, false, false))
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure the reason for doing this, but it seems like it would be better to check if the entire set matches. This could be written as a nested std::any_of but it should probably be a nested std::all_of.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's for #12377. We used to get stuck on pv, which actually has two values (get1 or get2).

Copy link
Owner

@danmar danmar left a comment

Choose a reason for hiding this comment

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

lgtm.. feel free to merge if paul is happy..

@chrchr-github
Copy link
Collaborator Author

@pfultz2 I think we should merge this, even if the ValueFlow is still wrong. As it stands, this check produces mostly FPs in daca.

@chrchr-github chrchr-github merged commit 503c109 into danmar:main Feb 9, 2024
64 checks passed
@chrchr-github chrchr-github deleted the chr_Fix11093 branch February 9, 2024 09:06
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