Skip to content

Commit 210232d

Browse files
committed
Fixed #9314 (false positive: (error) Uninitialized variable: ret)
1 parent cf5dd48 commit 210232d

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/checkuninitvar.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map<int, Var
244244
if (!tok)
245245
return;
246246

247+
if (tok->hasKnownIntValue()) {
248+
if (tok->getKnownIntValue() == 0)
249+
*alwaysFalse = true;
250+
else
251+
*alwaysTrue = true;
252+
return;
253+
}
254+
247255
if (tok->isName() || tok->str() == ".") {
248256
while (tok && tok->str() == ".")
249257
tok = tok->astOperand2();

test/testuninitvar.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,14 @@ class TestUninitVar : public TestFixture {
790790
"}");
791791
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: a\n", errout.str());
792792

793+
checkUninitVar("int foo() {\n"
794+
" int i;\n"
795+
" if (1)\n"
796+
" i = 11;\n"
797+
" return i;\n"
798+
"}");
799+
ASSERT_EQUALS("", errout.str());
800+
793801
checkUninitVar("int foo()\n"
794802
"{\n"
795803
" int i;\n"

0 commit comments

Comments
 (0)