Fixed #3290 (False positive: Null pointer dereference (typeid))
This commit is contained in:
parent
9996d38715
commit
8bbd535267
|
@ -900,7 +900,7 @@ void CheckNullPointer::nullConstantDereference()
|
|||
--indentlevel;
|
||||
}
|
||||
|
||||
if (tok->str() == "(" && Token::Match(tok->previous(), "sizeof|decltype"))
|
||||
if (tok->str() == "(" && Token::Match(tok->previous(), "sizeof|decltype|typeid"))
|
||||
tok = tok->link();
|
||||
|
||||
else if (Token::simpleMatch(tok, "exit ( )")) {
|
||||
|
@ -1064,7 +1064,7 @@ private:
|
|||
}
|
||||
|
||||
if (Token::Match(&tok, "%var% (")) {
|
||||
if (tok.str() == "sizeof")
|
||||
if (tok.str() == "sizeof" || tok.str() == "typeid")
|
||||
return tok.next()->link();
|
||||
|
||||
// parse usage..
|
||||
|
|
|
@ -1560,20 +1560,20 @@ private:
|
|||
" PolymorphicA* a = 0;\n"
|
||||
" return typeid(*a) == typeid(*a);\n"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("", "[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("struct NonPolymorphicA { ~A() {} };\n"
|
||||
"bool foo() {\n"
|
||||
" NonPolymorphicA* a = 0;\n"
|
||||
" return typeid(*a) == typeid(*a);\n"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("", "[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("bool foo() {\n"
|
||||
" char* c = 0;\n"
|
||||
" return typeid(*c) == typeid(*c);\n"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("", "[test.cpp:3]: (error) Null pointer dereference\n", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue