Skip to content

Commit 69f09da

Browse files
authored
Fix 11044: FP knownConditionTrueFalse after early return (#4091)
* Fix 11044: FP knownConditionTrueFalse after early return * Format
1 parent 16ef2c1 commit 69f09da

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

lib/astutils.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,20 +1689,6 @@ bool isConstFunctionCall(const Token* ftok, const Library& library)
16891689
} else if (f->argumentList.empty()) {
16901690
return f->isConstexpr();
16911691
}
1692-
} else if (const Library::Function* lf = library.getFunction(ftok)) {
1693-
if (lf->ispure)
1694-
return true;
1695-
for (auto&& p : lf->argumentChecks) {
1696-
const Library::ArgumentChecks& ac = p.second;
1697-
if (ac.direction != Library::ArgumentChecks::Direction::DIR_IN)
1698-
return false;
1699-
}
1700-
if (Token::simpleMatch(ftok->previous(), ".")) {
1701-
if (!lf->isconst)
1702-
return false;
1703-
} else if (lf->argumentChecks.empty()) {
1704-
return false;
1705-
}
17061692
} else if (Token::Match(ftok->previous(), ". %name% (") && ftok->previous()->originalName() != "->" &&
17071693
astIsSmartPointer(ftok->previous()->astOperand1())) {
17081694
return Token::Match(ftok, "get|get_deleter ( )");
@@ -1715,6 +1701,14 @@ bool isConstFunctionCall(const Token* ftok, const Library& library)
17151701
if (container->getAction(ftok->str()) == Library::Container::Action::FIND)
17161702
return true;
17171703
return false;
1704+
} else if (const Library::Function* lf = library.getFunction(ftok)) {
1705+
if (lf->ispure)
1706+
return true;
1707+
if (lf->containerYield != Library::Container::Yield::NO_YIELD)
1708+
return true;
1709+
if (lf->containerAction == Library::Container::Action::FIND)
1710+
return true;
1711+
return false;
17181712
} else {
17191713
bool memberFunction = Token::Match(ftok->previous(), ". %name% (");
17201714
bool constMember = !memberFunction;

test/testvalueflow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7215,6 +7215,12 @@ class TestValueFlow : public TestFixture {
72157215
"}\n";
72167216
ASSERT_EQUALS(false, testValueOfX(code, 6U, -1));
72177217
ASSERT_EQUALS(true, testValueOfXImpossible(code, 6U, -1));
7218+
7219+
code = "char* f() {\n"
7220+
" char *x = malloc(10);\n"
7221+
" return x;\n"
7222+
"}\n";
7223+
ASSERT_EQUALS(false, testValueOfX(code, 3U, "malloc(10)", 0));
72187224
}
72197225

72207226
void valueFlowSymbolicIdentity()

0 commit comments

Comments
 (0)