From 913dbeb8d8f9672e06565704a3da86b1223329db Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 2 Feb 2021 07:57:48 -0600 Subject: [PATCH] Fix FP when inserting a range into a container (#3108) --- lib/valueflow.cpp | 7 +++++-- test/testvalueflow.cpp | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 93f2f3c7c..bf4c3487d 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5736,8 +5736,11 @@ struct ContainerVariableAnalyzer : VariableAnalyzer { } } else if (Token::Match(tok, "%name% . %name% (")) { Library::Container::Action action = tok->valueType()->container->getAction(tok->strAt(2)); - if (action == Library::Container::Action::PUSH || action == Library::Container::Action::POP) - return Action::Read | Action::Write | Action::Incremental; + if (action == Library::Container::Action::PUSH || action == Library::Container::Action::POP) { + std::vector args = getArguments(tok->tokAt(3)); + if (args.size() < 2) + return Action::Read | Action::Write | Action::Incremental; + } } return Action::None; } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index ce53e5895..8cd4cfd6f 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5025,6 +5025,15 @@ private: " }\n" "}\n"; ASSERT_EQUALS(true, testValueOfXKnown(code, 4U, 0)); + + code = "std::vector g();\n" + "int f(bool b) {\n" + " std::set a;\n" + " std::vector 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() {