Skip to content

Commit

Permalink
Partial fix for #9157 False negative: stlOutOfBounds, cast (#4527)
Browse files Browse the repository at this point in the history
* Fix leakNoVarFunctionCall FP

* Partial fix for #9157 False negative: stlOutOfBounds, cast
  • Loading branch information
chrchr-github authored Sep 30, 2022
1 parent 858585c commit 586c29c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void CheckStl::outOfBounds()
return false;
const Token* sizeTok = v.tokvalue;
if (sizeTok && sizeTok->isCast())
sizeTok = sizeTok->astOperand1();
sizeTok = sizeTok->astOperand2() ? sizeTok->astOperand2() : sizeTok->astOperand1();
const Token* containerTok = getContainerFromSize(container, sizeTok);
if (!containerTok)
return false;
Expand Down
8 changes: 7 additions & 1 deletion test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,16 @@ class TestStl : public TestFixture {
" if (i <= (int)v.size()) {\n"
" if (v[i]) {}\n"
" }\n"
" if (i <= static_cast<int>(v.size())) {\n"
" if (v[i]) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("test.cpp:3:warning:Either the condition 'i<=(int)v.size()' is redundant or 'i' can have the value v.size(). Expression 'v[i]' cause access out of bounds.\n"
"test.cpp:2:note:condition 'i<=(int)v.size()'\n"
"test.cpp:3:note:Access out of bounds\n",
"test.cpp:3:note:Access out of bounds\n"
"test.cpp:6:warning:Either the condition 'i<=static_cast<int>(v.size())' is redundant or 'i' can have the value v.size(). Expression 'v[i]' cause access out of bounds.\n"
"test.cpp:5:note:condition 'i<=static_cast<int>(v.size())'\n"
"test.cpp:6:note:Access out of bounds\n",
errout.str());

check("template<class Iterator>\n"
Expand Down

0 comments on commit 586c29c

Please sign in to comment.