Fix FP when inserting a range into a container (#3108)

This commit is contained in:
Paul Fultz II 2021-02-02 07:57:48 -06:00 committed by GitHub
parent dc63dd6ada
commit 913dbeb8d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -5736,8 +5736,11 @@ struct ContainerVariableAnalyzer : VariableAnalyzer {
} }
} else if (Token::Match(tok, "%name% . %name% (")) { } else if (Token::Match(tok, "%name% . %name% (")) {
Library::Container::Action action = tok->valueType()->container->getAction(tok->strAt(2)); Library::Container::Action action = tok->valueType()->container->getAction(tok->strAt(2));
if (action == Library::Container::Action::PUSH || action == Library::Container::Action::POP) if (action == Library::Container::Action::PUSH || action == Library::Container::Action::POP) {
return Action::Read | Action::Write | Action::Incremental; std::vector<const Token*> args = getArguments(tok->tokAt(3));
if (args.size() < 2)
return Action::Read | Action::Write | Action::Incremental;
}
} }
return Action::None; return Action::None;
} }

View File

@ -5025,6 +5025,15 @@ private:
" }\n" " }\n"
"}\n"; "}\n";
ASSERT_EQUALS(true, testValueOfXKnown(code, 4U, 0)); ASSERT_EQUALS(true, testValueOfXKnown(code, 4U, 0));
code = "std::vector<int> g();\n"
"int f(bool b) {\n"
" std::set<int> a;\n"
" std::vector<int> c = g();\n"
" a.insert(c.begin(), c.end());\n"
" return a.size();\n"
"}\n";
ASSERT_EQUALS(true, tokenValues(code, "a . size", ValueFlow::Value::ValueType::CONTAINER_SIZE).empty());
} }
void valueFlowDynamicBufferSize() { void valueFlowDynamicBufferSize() {