parent
34317f86ab
commit
af0a585a70
|
@ -153,7 +153,10 @@ void CheckStl::outOfBounds()
|
||||||
return false;
|
return false;
|
||||||
if (v.intvalue < 0)
|
if (v.intvalue < 0)
|
||||||
return false;
|
return false;
|
||||||
const Token* containerTok = getContainerFromSize(container, v.tokvalue);
|
const Token* sizeTok = v.tokvalue;
|
||||||
|
if (sizeTok && sizeTok->isCast())
|
||||||
|
sizeTok = sizeTok->astOperand1();
|
||||||
|
const Token* containerTok = getContainerFromSize(container, sizeTok);
|
||||||
if (!containerTok)
|
if (!containerTok)
|
||||||
return false;
|
return false;
|
||||||
return containerTok->exprId() == tok->exprId();
|
return containerTok->exprId() == tok->exprId();
|
||||||
|
|
|
@ -682,6 +682,16 @@ private:
|
||||||
" return h(&v[0], v.size()); \n"
|
" return h(&v[0], v.size()); \n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkNormal("void f(int i, std::vector<int> v) {\n" // #9157
|
||||||
|
" if (i <= (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",
|
||||||
|
errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void outOfBoundsSymbolic()
|
void outOfBoundsSymbolic()
|
||||||
|
|
Loading…
Reference in New Issue