STL: Fixed outOfBounds false positive
This commit is contained in:
parent
9d26be8380
commit
996daaee4e
|
@ -87,7 +87,7 @@ void CheckStl::outOfBounds()
|
||||||
}
|
}
|
||||||
if (!container->arrayLike_indexOp && !container->stdStringLike)
|
if (!container->arrayLike_indexOp && !container->stdStringLike)
|
||||||
continue;
|
continue;
|
||||||
if (value.intvalue == 0 && Token::Match(parent, "[")) {
|
if (value.intvalue == 0 && Token::Match(parent, "[") && tok == parent->astOperand1()) {
|
||||||
outOfBoundsError(parent, tok->expressionString(), &value, "", nullptr);
|
outOfBoundsError(parent, tok->expressionString(), &value, "", nullptr);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,6 +305,12 @@ private:
|
||||||
" return (*pv)[42];\n"
|
" return (*pv)[42];\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("test.cpp:4:error:Out of bounds access in expression '(*pv)[42]' because '*pv' is empty.\n", errout.str());
|
ASSERT_EQUALS("test.cpp:4:error:Out of bounds access in expression '(*pv)[42]' because '*pv' is empty.\n", errout.str());
|
||||||
|
|
||||||
|
checkNormal("void f() {\n"
|
||||||
|
" std::string s;\n"
|
||||||
|
" ++abc[s];\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void outOfBoundsIndexExpression() {
|
void outOfBoundsIndexExpression() {
|
||||||
|
|
Loading…
Reference in New Issue