Skip to content

Commit 143ddf2

Browse files
authored
Fix 10595: FN: std::vector() reserve() (#3581)
* Fix 10595: FN: std::vector() reserve() * Format
1 parent 12e731a commit 143ddf2

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6850,12 +6850,12 @@ static bool isContainerSizeChanged(const Token* tok, const Settings* settings, i
68506850
case Library::Container::Action::CHANGE:
68516851
case Library::Container::Action::INSERT:
68526852
case Library::Container::Action::ERASE:
6853-
case Library::Container::Action::CHANGE_INTERNAL:
68546853
return true;
68556854
case Library::Container::Action::NO_ACTION: // might be unknown action
68566855
return yield == Library::Container::Yield::NO_YIELD;
68576856
case Library::Container::Action::FIND:
68586857
case Library::Container::Action::CHANGE_CONTENT:
6858+
case Library::Container::Action::CHANGE_INTERNAL:
68596859
break;
68606860
}
68616861
}

test/testvalueflow.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5818,6 +5818,15 @@ class TestValueFlow : public TestFixture {
58185818
" return v;\n"
58195819
"}\n";
58205820
ASSERT_EQUALS(true, tokenValues(code, "v [ 0 ] != 0 ) { }", ValueFlow::Value::ValueType::CONTAINER_SIZE).empty());
5821+
5822+
code = "std::vector<int> f() {\n"
5823+
" std::vector<int> v;\n"
5824+
" v.reserve(1);\n"
5825+
" v[1] = 42;\n"
5826+
" return v;\n"
5827+
"}\n";
5828+
ASSERT_EQUALS(
5829+
"", isKnownContainerSizeValue(tokenValues(code, "v [", ValueFlow::Value::ValueType::CONTAINER_SIZE), 0));
58215830
}
58225831

58235832
void valueFlowDynamicBufferSize() {

0 commit comments

Comments
 (0)