From 143ddf2758b50ade289669794641d4da52448bb3 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Fri, 26 Nov 2021 02:50:02 -0600 Subject: [PATCH] Fix 10595: FN: std::vector() reserve() (#3581) * Fix 10595: FN: std::vector() reserve() * Format --- lib/valueflow.cpp | 2 +- test/testvalueflow.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index e2b6e6fc8..0e9cda6ae 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6850,12 +6850,12 @@ static bool isContainerSizeChanged(const Token* tok, const Settings* settings, i case Library::Container::Action::CHANGE: case Library::Container::Action::INSERT: case Library::Container::Action::ERASE: - case Library::Container::Action::CHANGE_INTERNAL: return true; case Library::Container::Action::NO_ACTION: // might be unknown action return yield == Library::Container::Yield::NO_YIELD; case Library::Container::Action::FIND: case Library::Container::Action::CHANGE_CONTENT: + case Library::Container::Action::CHANGE_INTERNAL: break; } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 68e07372a..c6bfca4e6 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5818,6 +5818,15 @@ private: " return v;\n" "}\n"; ASSERT_EQUALS(true, tokenValues(code, "v [ 0 ] != 0 ) { }", ValueFlow::Value::ValueType::CONTAINER_SIZE).empty()); + + code = "std::vector f() {\n" + " std::vector v;\n" + " v.reserve(1);\n" + " v[1] = 42;\n" + " return v;\n" + "}\n"; + ASSERT_EQUALS( + "", isKnownContainerSizeValue(tokenValues(code, "v [", ValueFlow::Value::ValueType::CONTAINER_SIZE), 0)); } void valueFlowDynamicBufferSize() {