Skip to content

Commit 6278f6b

Browse files
Fix #14721 FP container considered empty after insertion (*m)[1] = 42; (#8529)
1 parent efae8c0 commit 6278f6b

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lib/valueflow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6221,6 +6221,8 @@ bool ValueFlow::isContainerSizeChanged(const Token* tok, int indirect, const Set
62216221
return true;
62226222
if (astIsLHS(tok) && Token::simpleMatch(tok->astParent(), "["))
62236223
return tok->valueType()->container->stdAssociativeLike;
6224+
if (Token::simpleMatch(tok->astParent(), "*") && indirect > 0)
6225+
return isContainerSizeChanged(tok->astParent(), indirect - 1, settings, depth + 1);
62246226
const Library::Container::Action action = astContainerAction(tok, settings.library);
62256227
switch (action) {
62266228
case Library::Container::Action::RESIZE:

test/testvalueflow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7486,6 +7486,16 @@ class TestValueFlow : public TestFixture {
74867486
" if (s.empty()) {}\n"
74877487
"}";
74887488
ASSERT(!isKnownContainerSizeValue(tokenValues(code, "s ."), 0).empty());
7489+
7490+
code = "void g(std::map<int, int>* p) {\n" // #14721
7491+
" (*p)[1] = 2;\n"
7492+
"}\n"
7493+
"void f() {\n"
7494+
" std::map<int, int> m;\n"
7495+
" g(&m);\n"
7496+
" if (m.empty()) {}\n"
7497+
"}\n";
7498+
ASSERT(!isKnownContainerSizeValue(tokenValues(code, "m ."), 0).empty());
74897499
}
74907500

74917501
void valueFlowContainerElement()

0 commit comments

Comments
 (0)