Skip to content

Commit

Permalink
Extend
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed May 10, 2024
1 parent edf77af commit c296c8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
if (Token::simpleMatch(tokAssignOp->astOperand1(), "."))
continue;
// taking address of another variable..
if (Token::Match(tokAssignOp, "= %var% [+;?]")) {
if (Token::Match(tokAssignOp, "= %var% +|;|?|%comp%")) {
if (varTok->tokAt(2)->varId() != varTok->varId()) {
// If variable points at allocated memory => error
leakIfAllocated(varTok, varInfo);
Expand Down
6 changes: 6 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,12 @@ class TestLeakAutoVar : public TestFixture {
" x = p ? p : nullptr;\n"
"}", true);
ASSERT_EQUALS("", errout_str());

check("void f(int*& x) {\n"
" int* p = (int*)malloc(10);\n"
" x = p != nullptr ? p : nullptr;\n"
"}", true);
ASSERT_EQUALS("", errout_str());
}

void isAutoDealloc() {
Expand Down

0 comments on commit c296c8d

Please sign in to comment.