Skip to content

Commit c3e47f7

Browse files
committed
Fixed false positive in CheckUninitVar and internal message
1 parent 94c3c45 commit c3e47f7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/checkuninitvar.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
14381438
}
14391439

14401440
// bailout on ternary operator. TODO: This can be solved much better. For example, if the variable is not accessed in the branches of the ternary operator, we could just continue.
1441-
if (Token::Match(tok, "?")) {
1441+
if (tok->str() == "?") {
14421442
return true;
14431443
}
14441444

@@ -1706,6 +1706,12 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
17061706
assignment = true;
17071707
break;
17081708
}
1709+
if (alloc && parent->str() == "(") {
1710+
if (_settings->library.functionpure.find(parent->strAt(-1)) == _settings->library.functionpure.end()) {
1711+
assignment = true;
1712+
break;
1713+
}
1714+
}
17091715
parent = parent->astParent();
17101716
}
17111717
if (!assignment)

test/testuninitvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ class TestUninitVar : public TestFixture {
14701470
" Fred *fred = malloc(sizeof(Fred));\n"
14711471
" x(fred->f);\n"
14721472
"};");
1473-
TODO_ASSERT_EQUALS("", "[test.cpp:4]: (error) Memory is allocated but not initialized: fred\n", errout.str());
1473+
ASSERT_EQUALS("", errout.str());
14741474

14751475
checkUninitVarB("void foo(char *s)\n"
14761476
"{\n"

0 commit comments

Comments
 (0)