Bug hunting: Avoid uninitialized fp for smart pointer

This commit is contained in:
Daniel Marjamäki 2020-09-07 09:13:31 +02:00
parent a4f43fc2ad
commit 06c4b8897b
2 changed files with 14 additions and 0 deletions

View File

@ -247,6 +247,10 @@ static void uninit(const Token *tok, const ExprEngine::Value &value, ExprEngine:
return; return;
} }
// smart pointer is not uninitialized
if (tok->variable() && !tok->variable()->isPointer() && tok->variable()->isSmartPointer())
return;
// lhs in assignment // lhs in assignment
if (tok->astParent()->str() == "=" && tok == tok->astParent()->astOperand1()) if (tok->astParent()->str() == "=" && tok == tok->astParent()->astOperand1())
return; return;

View File

@ -42,6 +42,7 @@ 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(ctu); TEST_CASE(ctu);
#endif #endif
} }
@ -175,6 +176,15 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void uninit_fp_try_smartptr() {
check("void foo() {\n"
" std::unique_ptr<std::string> buffer;\n"
" try { } catch (std::exception& e) { }\n"
" doneCallback(std::move(buffer));\n"
"}");
ASSERT_EQUALS("", errout.str());
}
}; };
REGISTER_TEST(TestBughuntingChecks) REGISTER_TEST(TestBughuntingChecks)