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() {