Better support for funciton pointers in checkuninitvar.cpp (#6404)
This commit is contained in:
parent
6b20172a36
commit
0d151b45b5
|
@ -1072,6 +1072,10 @@ void CheckUninitVar::checkScope(const Scope* scope)
|
||||||
checkRhs(i->nameToken(), *i, NO_ALLOC, "");
|
checkRhs(i->nameToken(), *i, NO_ALLOC, "");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (Token::Match(i->nameToken(), "%var% ) (") && Token::simpleMatch(i->nameToken()->linkAt(2), ") =")) { // Function pointer is initialized, but Rhs might be not
|
||||||
|
checkRhs(i->nameToken()->linkAt(2)->next(), *i, NO_ALLOC, "");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
bool stdtype = _tokenizer->isC();
|
bool stdtype = _tokenizer->isC();
|
||||||
const Token* tok = i->typeStartToken();
|
const Token* tok = i->typeStartToken();
|
||||||
|
|
|
@ -71,6 +71,7 @@ private:
|
||||||
TEST_CASE(uninitvar8); // ticket #6230
|
TEST_CASE(uninitvar8); // ticket #6230
|
||||||
TEST_CASE(uninitvar9); // ticket #6424
|
TEST_CASE(uninitvar9); // ticket #6424
|
||||||
TEST_CASE(uninitvar_unconditionalTry);
|
TEST_CASE(uninitvar_unconditionalTry);
|
||||||
|
TEST_CASE(uninitvar_funcptr); // #6404
|
||||||
|
|
||||||
TEST_CASE(syntax_error); // Ticket #5073
|
TEST_CASE(syntax_error); // Ticket #5073
|
||||||
|
|
||||||
|
@ -2825,6 +2826,28 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: i\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uninitvar_funcptr() {
|
||||||
|
checkUninitVar2("void getLibraryContainer() {\n"
|
||||||
|
" Reference< XStorageBasedLibraryContainer >(*Factory)(const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&)\n"
|
||||||
|
" = &DocumentDialogLibraryContainer::create;\n"
|
||||||
|
" rxContainer.set((*Factory)(m_aContext, xDocument));\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar2("void getLibraryContainer() {\n"
|
||||||
|
" void* x;\n"
|
||||||
|
" Reference< XStorageBasedLibraryContainer >(*Factory)(const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&)\n"
|
||||||
|
" = x;\n"
|
||||||
|
" rxContainer.set((*Factory)(m_aContext, xDocument));\n"
|
||||||
|
"}", "test.cpp", false);
|
||||||
|
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar2("void getLibraryContainer() {\n"
|
||||||
|
" Reference< XStorageBasedLibraryContainer >(*Factory)(const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&);\n"
|
||||||
|
" rxContainer.set((*Factory)(m_aContext, xDocument));\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: Factory\n", errout.str());
|
||||||
|
}
|
||||||
// Handling of function calls
|
// Handling of function calls
|
||||||
void uninitvar2_func() {
|
void uninitvar2_func() {
|
||||||
// non-pointer variable
|
// non-pointer variable
|
||||||
|
|
Loading…
Reference in New Issue