Fix 10394 and 10395: FP knownConditionTrueFalse: loop variable (#3381)
This commit is contained in:
parent
8b8ae55490
commit
735f716603
|
@ -4113,6 +4113,8 @@ static void valueFlowSymbolic(TokenList* tokenlist, SymbolDatabase* symboldataba
|
||||||
for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
|
for (Token* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
|
||||||
if (!Token::simpleMatch(tok, "="))
|
if (!Token::simpleMatch(tok, "="))
|
||||||
continue;
|
continue;
|
||||||
|
if (tok->astParent())
|
||||||
|
continue;
|
||||||
if (!tok->astOperand1())
|
if (!tok->astOperand1())
|
||||||
continue;
|
continue;
|
||||||
if (!tok->astOperand2())
|
if (!tok->astOperand2())
|
||||||
|
|
|
@ -1206,10 +1206,7 @@ private:
|
||||||
" for (x = a; x < 50; x++) {}\n"
|
" for (x = a; x < 50; x++) {}\n"
|
||||||
" b = x;\n"
|
" b = x;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS("3,x is assigned 'a' here.\n"
|
ASSERT_EQUALS("3,After for loop, x has value 50\n",
|
||||||
"3,x is incremented', new value is symbolic=a+1\n"
|
|
||||||
"3,x is incremented', new value is symbolic=a+2\n"
|
|
||||||
"3,After for loop, x has value 50\n",
|
|
||||||
getErrorPathForX(code, 4U));
|
getErrorPathForX(code, 4U));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6021,6 +6018,17 @@ private:
|
||||||
" return x;\n"
|
" return x;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 1));
|
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 1));
|
||||||
|
|
||||||
|
code = "int f(int i) {\n"
|
||||||
|
" for(int j = i;;j++) {\n"
|
||||||
|
" int x = j;\n"
|
||||||
|
" return x;\n"
|
||||||
|
" }\n"
|
||||||
|
" return 0;\n"
|
||||||
|
"}\n";
|
||||||
|
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, "i", 0));
|
||||||
|
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, "i", 1));
|
||||||
|
ASSERT_EQUALS(true, testValueOfXKnown(code, 4U, "j", 0));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue