Skip to content

Commit

Permalink
Fix #12993 FP containerOutOfBounds with array of strings (#6667)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Aug 7, 2024
1 parent bf6ae27 commit 26a266a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7141,6 +7141,8 @@ static void valueFlowContainerSize(const TokenList& tokenlist,
const Token* containerTok = tok->astOperand1();
if (containerTok->exprId() == 0)
continue;
if (containerTok->variable() && containerTok->variable()->isArray())
continue;
const Library::Container::Action action = containerTok->valueType()->container->getAction(tok->strAt(1));
if (action == Library::Container::Action::CLEAR) {
ValueFlow::Value value(0);
Expand Down
7 changes: 7 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6942,6 +6942,13 @@ class TestValueFlow : public TestFixture {
" return x;\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXKnown(code, 5U, 1));

code = "std::string f() {\n" // #12993
" std::string a[1];\n"
" a->clear();\n"
" return a[0];\n"
"}\n";
ASSERT(!isKnownContainerSizeValue(tokenValues(code, "a [ 0"), 0).empty());
}

void valueFlowContainerElement()
Expand Down

0 comments on commit 26a266a

Please sign in to comment.