Bug hunting; avoid uninit var fp for struct variables
This commit is contained in:
parent
cfd41fea83
commit
07f6876dc8
|
@ -247,13 +247,20 @@ static void uninit(const Token *tok, const ExprEngine::Value &value, ExprEngine:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// smart pointer is not uninitialized
|
// variable that is not uninitialized..
|
||||||
if (tok->variable() && !tok->variable()->isPointer() && tok->variable()->isSmartPointer())
|
if (tok->variable() && !tok->variable()->isPointer() && !tok->variable()->isReference()) {
|
||||||
return;
|
// smart pointer is not uninitialized
|
||||||
|
if (tok->variable()->isSmartPointer())
|
||||||
|
return;
|
||||||
|
|
||||||
// template variable is not uninitialized
|
// struct
|
||||||
if (tok->variable() && !tok->variable()->isPointer() && Token::findmatch(tok->variable()->typeStartToken(), "%name% <", tok->variable()->typeEndToken()))
|
if (tok->variable()->type() && tok->variable()->type()->needInitialization == Type::NeedInitialization::False)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// template variable is not uninitialized
|
||||||
|
if (Token::findmatch(tok->variable()->typeStartToken(), "%name% <", tok->variable()->typeEndToken()))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// lhs in assignment
|
// lhs in assignment
|
||||||
if (tok->astParent()->str() == "=" && tok == tok->astParent()->astOperand1())
|
if (tok->astParent()->str() == "=" && tok == tok->astParent()->astOperand1())
|
||||||
|
|
|
@ -42,7 +42,8 @@ private:
|
||||||
TEST_CASE(uninit_malloc);
|
TEST_CASE(uninit_malloc);
|
||||||
TEST_CASE(uninit_struct);
|
TEST_CASE(uninit_struct);
|
||||||
TEST_CASE(uninit_bailout);
|
TEST_CASE(uninit_bailout);
|
||||||
TEST_CASE(uninit_fp_try_smartptr);
|
TEST_CASE(uninit_fp_smartptr);
|
||||||
|
TEST_CASE(uninit_fp_struct);
|
||||||
TEST_CASE(uninit_fp_template_var);
|
TEST_CASE(uninit_fp_template_var);
|
||||||
TEST_CASE(ctu);
|
TEST_CASE(ctu);
|
||||||
#endif
|
#endif
|
||||||
|
@ -178,7 +179,7 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninit_fp_try_smartptr() {
|
void uninit_fp_smartptr() {
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" std::unique_ptr<std::string> buffer;\n"
|
" std::unique_ptr<std::string> buffer;\n"
|
||||||
" try { } catch (std::exception& e) { }\n"
|
" try { } catch (std::exception& e) { }\n"
|
||||||
|
@ -187,6 +188,20 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uninit_fp_struct() {
|
||||||
|
check("struct Pos {\n"
|
||||||
|
" int x {0};\n"
|
||||||
|
" int y {0};\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"void dostuff() {\n"
|
||||||
|
" auto obj = C {};\n"
|
||||||
|
" Pos xy;\n"
|
||||||
|
" foo(xy);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void uninit_fp_template_var() {
|
void uninit_fp_template_var() {
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" X*x = DYNAMIC_CAST(X, p);\n"
|
" X*x = DYNAMIC_CAST(X, p);\n"
|
||||||
|
|
Loading…
Reference in New Issue