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 #13001 knownConditionTrueFalse with QVector::append() #6687

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cfg/qt.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5078,7 +5078,7 @@
<container id="qtContainer" endPattern="&gt; !!::" opLessAllowed="false" itEndPattern="&gt; :: iterator|const_iterator">
<type templateParameter="0"/>
<size>
<function name="append" action="push"/>
<function name="append" action="append"/>
<function name="clear" action="clear"/>
<function name="count" yields="size"/>
<function name="erase" action="erase"/>
Expand Down
4 changes: 4 additions & 0 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6574,6 +6574,10 @@ struct ContainerExpressionAnalyzer : ExpressionAnalyzer {
n = -1;
break;
case Library::Container::Action::APPEND: {
if (!container->stdStringLike) {
val->setPossible(); // TODO: use appendee's size
break;
}
std::vector<const Token*> args = getArguments(tok->astParent()->tokAt(2));
if (args.size() == 1) // TODO: handle overloads
n = valueFlowGetStrLength(tok->astParent()->tokAt(3));
Expand Down
7 changes: 7 additions & 0 deletions test/cfg/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ QList<int>::iterator QList3()
return it;
}

void QList4() // #13001
{
QList<int> ql;
ql.append(QList<int>());
if (ql.isEmpty()) {}
}

void QLinkedList1()
{
// cppcheck-suppress unreadVariable
Expand Down
Loading