Fix issue 9935: FP: knownConditionTrueFalse value flow doesn't account for virtual functions (#2839)
This commit is contained in:
parent
586ddf74f1
commit
047c3ed6ba
|
@ -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)
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue