containerAccessOutOfBounds: Fix FPs for maps etc
This commit is contained in:
parent
c4000b27f8
commit
0e30bdef9d
|
@ -72,6 +72,8 @@ void CheckStl::outOfBounds()
|
||||||
outOfBoundsError(tok, &value, nullptr);
|
outOfBoundsError(tok, &value, nullptr);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!container->arrayLike_indexOp && !container->stdStringLike)
|
||||||
|
continue;
|
||||||
if (value.intvalue == 0 && Token::Match(tok, "%name% [")) {
|
if (value.intvalue == 0 && Token::Match(tok, "%name% [")) {
|
||||||
outOfBoundsError(tok, &value, nullptr);
|
outOfBoundsError(tok, &value, nullptr);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -216,6 +216,20 @@ private:
|
||||||
" v[i] = 0;\n"
|
" v[i] = 0;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkNormal("void f(std::map<int,int> x) {\n"
|
||||||
|
" if (x.empty()) { x[1] = 2; }\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkNormal("void f(std::string s) {\n"
|
||||||
|
" if (s.size() == 1) {\n"
|
||||||
|
" s[2] = 0;\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("test.cpp:3:warning:Possible access out of bounds of container 's'; size=1, index=2\n"
|
||||||
|
"test.cpp:2:note:condition 's.size()==1'\n"
|
||||||
|
"test.cpp:3:note:Access out of bounds\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void iterator1() {
|
void iterator1() {
|
||||||
|
|
Loading…
Reference in New Issue