Fix issue 9894: ValueFlow: wrong known value below while with assignment (#2804)
* Fix issue 9894: ValueFlow: wrong known value below while with assignment
This commit is contained in:
parent
ebb5ff0e19
commit
bb7164171c
|
@ -4510,9 +4510,10 @@ struct ValueFlowConditionHandler {
|
|||
if (Token::simpleMatch(top->link(), ") {")) {
|
||||
Token *after = top->link()->linkAt(1);
|
||||
const Token* unknownFunction = nullptr;
|
||||
bool dead_if = isReturnScope(after, &settings->library, &unknownFunction) ||
|
||||
(tok->astParent() && Token::simpleMatch(tok->astParent()->previous(), "while (") &&
|
||||
!isBreakScope(after));
|
||||
const bool isWhile =
|
||||
tok->astParent() && Token::simpleMatch(tok->astParent()->previous(), "while (");
|
||||
bool dead_if = (!isBreakScope(after) && isWhile) ||
|
||||
(isReturnScope(after, &settings->library, &unknownFunction) && !isWhile);
|
||||
bool dead_else = false;
|
||||
|
||||
if (!dead_if && unknownFunction) {
|
||||
|
|
|
@ -2478,6 +2478,20 @@ private:
|
|||
" return x;\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(false, testValueOfXImpossible(code, 8U, 0));
|
||||
|
||||
code = "bool c();\n"
|
||||
"long f() {\n"
|
||||
" bool stop = false;\n"
|
||||
" while (!stop) {\n"
|
||||
" if (c())\n"
|
||||
" stop = true;\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" int x = !stop;\n"
|
||||
" return x;\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(false, testValueOfXImpossible(code, 10U, 1));
|
||||
ASSERT_EQUALS(false, testValueOfXKnown(code, 10U, 0));
|
||||
}
|
||||
|
||||
void valueFlowAfterConditionExpr() {
|
||||
|
|
Loading…
Reference in New Issue