Partial fix for #9157 False negative: stlOutOfBounds, cast (#4527)

* Fix leakNoVarFunctionCall FP

* Partial fix for #9157 False negative: stlOutOfBounds, cast
This commit is contained in:
chrchr-github 2022-09-30 14:43:21 +02:00 committed by GitHub
parent 858585ceb1
commit 586c29c772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -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;

View File

@ -690,10 +690,16 @@ private:
" 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"