Skip to content

Commit

Permalink
Fix #12662 FP unreadVariable with QMap iterator (#6354)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Apr 28, 2024
1 parent b3f3606 commit e4f7087
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/fwdanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) co
return true;
if (Token::simpleMatch(expr, ". *"))
return true;
if (expr->str() == "(" && Token::simpleMatch(expr->astOperand1(), "."))
return true;

const bool macro = false;
const bool pure = false;
Expand Down
10 changes: 10 additions & 0 deletions test/cfg/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,3 +775,13 @@ void unusedVariable_qtContainers() // #10689
QLatin1String ql1s;
}

void unreadVariable_QMapIterator(QMap<QString, QObject*>& m)
{
auto it = m.find("abc"); // #12662
if (it != m.end()) {
// cppcheck-suppress checkLibraryFunction // TODO
delete it.value();
// cppcheck-suppress checkLibraryFunction
it.value() = new QObject();
}
}

0 comments on commit e4f7087

Please sign in to comment.