Fix 11044: FP knownConditionTrueFalse after early return (#4091)

* Fix 11044: FP knownConditionTrueFalse after early return

* Format
This commit is contained in:
Paul Fultz II 2022-05-09 13:26:52 -05:00 committed by GitHub
parent 16ef2c1838
commit 69f09da63e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 14 deletions

View File

@ -1689,20 +1689,6 @@ bool isConstFunctionCall(const Token* ftok, const Library& library)
} else if (f->argumentList.empty()) {
return f->isConstexpr();
}
} else if (const Library::Function* lf = library.getFunction(ftok)) {
if (lf->ispure)
return true;
for (auto&& p : lf->argumentChecks) {
const Library::ArgumentChecks& ac = p.second;
if (ac.direction != Library::ArgumentChecks::Direction::DIR_IN)
return false;
}
if (Token::simpleMatch(ftok->previous(), ".")) {
if (!lf->isconst)
return false;
} else if (lf->argumentChecks.empty()) {
return false;
}
} else if (Token::Match(ftok->previous(), ". %name% (") && ftok->previous()->originalName() != "->" &&
astIsSmartPointer(ftok->previous()->astOperand1())) {
return Token::Match(ftok, "get|get_deleter ( )");
@ -1715,6 +1701,14 @@ bool isConstFunctionCall(const Token* ftok, const Library& library)
if (container->getAction(ftok->str()) == Library::Container::Action::FIND)
return true;
return false;
} else if (const Library::Function* lf = library.getFunction(ftok)) {
if (lf->ispure)
return true;
if (lf->containerYield != Library::Container::Yield::NO_YIELD)
return true;
if (lf->containerAction == Library::Container::Action::FIND)
return true;
return false;
} else {
bool memberFunction = Token::Match(ftok->previous(), ". %name% (");
bool constMember = !memberFunction;

View File

@ -7215,6 +7215,12 @@ private:
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 6U, -1));
ASSERT_EQUALS(true, testValueOfXImpossible(code, 6U, -1));
code = "char* f() {\n"
" char *x = malloc(10);\n"
" return x;\n"
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 3U, "malloc(10)", 0));
}
void valueFlowSymbolicIdentity()