Fixed #9062 (False positive "condition is always true")

This commit is contained in:
Daniel Marjamäki 2019-07-24 19:16:35 +02:00
parent e11dcc609b
commit bbcffce529
2 changed files with 11 additions and 1 deletions

View File

@ -1512,7 +1512,7 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
if (Token::simpleMatch(tok, "asm (")) if (Token::simpleMatch(tok, "asm ("))
return Result(Result::Type::BAILOUT); return Result(Result::Type::BAILOUT);
if (mWhat == What::ValueFlow && Token::Match(tok, "while|for (")) { if (mWhat == What::ValueFlow && (Token::Match(tok, "while|for (") || Token::simpleMatch(tok, "do {"))) {
// TODO: only bailout if expr is reassigned in loop // TODO: only bailout if expr is reassigned in loop
return Result(Result::Type::BAILOUT); return Result(Result::Type::BAILOUT);
} }

View File

@ -2585,6 +2585,16 @@ private:
values = tokenValues(code, ">"); values = tokenValues(code, ">");
ASSERT_EQUALS(true, values.empty()); ASSERT_EQUALS(true, values.empty());
code = "void foo() {\n"
" struct ISO_PVD_s pvd;\n"
" pvd.descr_type = 0xff;\n"
" do {\n"
" if (pvd.descr_type == 0xff) {}\n"
" dostuff(&pvd);\n"
" } while (condition)\n"
"}";
values = tokenValues(code, "==");
ASSERT_EQUALS(true, values.empty());
} }
void valueFlowSwitchVariable() { void valueFlowSwitchVariable() {