Fixed #5255 (False positive (error) Uninitialized variable: ptr2 - calling a static member function)
This commit is contained in:
parent
e2fa6a291c
commit
661784a170
|
@ -514,6 +514,11 @@ private:
|
|||
|
||||
if (Token::Match(tok.previous(), "[;{}] %var% [=[.]")) {
|
||||
if (tok.next()->str() == ".") {
|
||||
if (Token::Match(&tok, "%var% . %var% (")) {
|
||||
const Function *function = tok.tokAt(2)->function();
|
||||
if (function && function->isStatic)
|
||||
return &tok;
|
||||
}
|
||||
if (use_dead_pointer(checks, &tok)) {
|
||||
return &tok;
|
||||
}
|
||||
|
@ -1770,7 +1775,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
|
|||
}
|
||||
|
||||
bool unknown = false;
|
||||
if (pointer && (CheckNullPointer::isPointerDeRef(vartok, unknown) || Token::Match(vartok, "%var% ."))) {
|
||||
if (pointer && CheckNullPointer::isPointerDeRef(vartok, unknown)) {
|
||||
// pointer is allocated - dereferencing it is ok.
|
||||
if (alloc)
|
||||
return false;
|
||||
|
@ -1785,6 +1790,11 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
|
|||
return true;
|
||||
}
|
||||
|
||||
if (pointer && Token::Match(vartok, "%var% . %var% (")) {
|
||||
const Function *function = vartok->tokAt(2)->function();
|
||||
return (!function || !function->isStatic);
|
||||
}
|
||||
|
||||
if (cpp && Token::Match(vartok->next(), "<<|>>")) {
|
||||
// Is this calculation done in rhs?
|
||||
const Token *tok = vartok;
|
||||
|
|
|
@ -356,6 +356,16 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #5255
|
||||
checkUninitVar("struct Element {\n"
|
||||
" static void abcd() {}\n"
|
||||
"};\n"
|
||||
"void a() {\n"
|
||||
" Element *e;\n"
|
||||
" e->abcd();\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Handling >> and <<
|
||||
{
|
||||
checkUninitVar("int a() {\n"
|
||||
|
@ -3075,6 +3085,14 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: ptr3\n", errout.str());
|
||||
|
||||
checkUninitVar2("class Element {\n"
|
||||
" static void f() { }\n"
|
||||
"};\n"
|
||||
"void test() {\n"
|
||||
" Element *element; element->f();\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar2("void f() {\n" // #4911 - bad simplification => don't crash
|
||||
" int a;\n"
|
||||
" do { } a=do_something(); while (a);\n"
|
||||
|
|
Loading…
Reference in New Issue