From acfff072ae8200e399e0f6d3f030e5ee9b435e44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 7 Sep 2020 16:25:37 +0200 Subject: [PATCH] Bug hunting; avoid bughuntingUninitVar fp for template variable --- lib/bughuntingchecks.cpp | 4 ++++ test/testbughuntingchecks.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/bughuntingchecks.cpp b/lib/bughuntingchecks.cpp index f3eb8e8dd..3f0819996 100644 --- a/lib/bughuntingchecks.cpp +++ b/lib/bughuntingchecks.cpp @@ -251,6 +251,10 @@ static void uninit(const Token *tok, const ExprEngine::Value &value, ExprEngine: if (tok->variable() && !tok->variable()->isPointer() && tok->variable()->isSmartPointer()) return; + // template variable is not uninitialized + if (tok->variable() && !tok->variable()->isPointer() && Token::findmatch(tok->variable()->typeStartToken(), "%name% <", tok->variable()->typeEndToken())) + return; + // lhs in assignment if (tok->astParent()->str() == "=" && tok == tok->astParent()->astOperand1()) return; diff --git a/test/testbughuntingchecks.cpp b/test/testbughuntingchecks.cpp index d051851b9..c73d74d52 100644 --- a/test/testbughuntingchecks.cpp +++ b/test/testbughuntingchecks.cpp @@ -43,6 +43,7 @@ private: TEST_CASE(uninit_struct); TEST_CASE(uninit_bailout); TEST_CASE(uninit_fp_try_smartptr); + TEST_CASE(uninit_fp_template_var); TEST_CASE(ctu); #endif } @@ -185,6 +186,15 @@ private: "}"); ASSERT_EQUALS("", errout.str()); } + + void uninit_fp_template_var() { + check("void foo() {\n" + " X*x = DYNAMIC_CAST(X, p);\n" + " C c;\n" + " f(c);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestBughuntingChecks)