Fix issue 9935: FP: knownConditionTrueFalse value flow doesn't account for virtual functions (#2839)

This commit is contained in:
Paul Fultz II 2020-10-09 10:21:27 -05:00 committed by GitHub
parent 586ddf74f1
commit 047c3ed6ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -5858,7 +5858,7 @@ static bool isContainerSizeChangedByFunction(const Token *tok, int depth = 20)
if (!ftok)
return false; // not a function => variable not changed
const Function * fun = ftok->function();
if (fun) {
if (fun && !fun->hasVirtualSpecifier()) {
const Variable *arg = fun->getArgumentVar(narg);
if (arg) {
if (!arg->isReference() && !addressOf)

View File

@ -4657,6 +4657,21 @@ private:
" return m.at(0);\n"
"}\n";
ASSERT_EQUALS("", isPossibleContainerSizeValue(tokenValues(code, "m . at", ValueFlow::Value::CONTAINER_SIZE), 0));
code = "struct Base {\n"
" virtual bool GetString(std::string &) const { return false; }\n"
"};\n"
"int f() {\n"
" std::string str;\n"
" Base *b = GetClass();\n"
" if (!b->GetString(str)) {\n"
" return -2;\n"
" }\n"
" else {\n"
" return str.front();\n"
" }\n"
"}\n";
ASSERT_EQUALS(0U, tokenValues(code, "str . front").size());
}
void valueFlowDynamicBufferSize() {