Fix 10595: FN: std::vector() reserve() (#3581)

* Fix 10595: FN: std::vector() reserve()

* Format
This commit is contained in:
Paul Fultz II 2021-11-26 02:50:02 -06:00 committed by GitHub
parent 12e731ad49
commit 143ddf2758
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -6850,12 +6850,12 @@ static bool isContainerSizeChanged(const Token* tok, const Settings* settings, i
case Library::Container::Action::CHANGE: case Library::Container::Action::CHANGE:
case Library::Container::Action::INSERT: case Library::Container::Action::INSERT:
case Library::Container::Action::ERASE: case Library::Container::Action::ERASE:
case Library::Container::Action::CHANGE_INTERNAL:
return true; return true;
case Library::Container::Action::NO_ACTION: // might be unknown action case Library::Container::Action::NO_ACTION: // might be unknown action
return yield == Library::Container::Yield::NO_YIELD; return yield == Library::Container::Yield::NO_YIELD;
case Library::Container::Action::FIND: case Library::Container::Action::FIND:
case Library::Container::Action::CHANGE_CONTENT: case Library::Container::Action::CHANGE_CONTENT:
case Library::Container::Action::CHANGE_INTERNAL:
break; break;
} }
} }

View File

@ -5818,6 +5818,15 @@ private:
" return v;\n" " return v;\n"
"}\n"; "}\n";
ASSERT_EQUALS(true, tokenValues(code, "v [ 0 ] != 0 ) { }", ValueFlow::Value::ValueType::CONTAINER_SIZE).empty()); ASSERT_EQUALS(true, tokenValues(code, "v [ 0 ] != 0 ) { }", ValueFlow::Value::ValueType::CONTAINER_SIZE).empty());
code = "std::vector<int> f() {\n"
" std::vector<int> 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() { void valueFlowDynamicBufferSize() {