null pointers: fixed a false positive
This commit is contained in:
parent
f406babc32
commit
e6713e9774
|
@ -1042,6 +1042,9 @@ void CheckOther::nullPointer()
|
||||||
if (varid == 0)
|
if (varid == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (Token::Match(tok2->tokAt(-2), "%varid% ?", varid))
|
||||||
|
continue;
|
||||||
|
|
||||||
// Check usage of dereferenced variable in the loop..
|
// Check usage of dereferenced variable in the loop..
|
||||||
unsigned int indentlevel3 = 0;
|
unsigned int indentlevel3 = 0;
|
||||||
for (const Token *tok3 = tok1->next()->link(); tok3; tok3 = tok3->next())
|
for (const Token *tok3 = tok1->next()->link(); tok3; tok3 = tok3->next())
|
||||||
|
|
|
@ -446,6 +446,16 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference\n", errout.str());
|
||||||
|
|
||||||
|
checkNullPointer("void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" for (const Token *tok = tokens; tok; tok = tok ? tok->next() : NULL)\n"
|
||||||
|
" {\n"
|
||||||
|
" while (tok && tok->str() != \";\")\n"
|
||||||
|
" tok = tok->next();\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void nullpointer2()
|
void nullpointer2()
|
||||||
|
|
Loading…
Reference in New Issue