Fix issue 10035: FP: knownConditionTrueFalse when bool updated in for loop (#2953)
This commit is contained in:
parent
fd520b45d7
commit
c9d2e55ea9
|
@ -507,18 +507,16 @@ void execute(const Token *expr,
|
|||
else {
|
||||
bool error2 = false;
|
||||
execute(expr->astOperand2(), programMemory, result, &error2);
|
||||
if (error1 && error2)
|
||||
if (error1 || error2)
|
||||
*error = true;
|
||||
if (error2)
|
||||
*result = 1;
|
||||
else
|
||||
*result = !!*result;
|
||||
}
|
||||
}
|
||||
|
||||
else if (expr->str() == "||") {
|
||||
execute(expr->astOperand1(), programMemory, result, error);
|
||||
if (*result == 0 && *error == false)
|
||||
if (*result == 1 && *error == false)
|
||||
*result = 1;
|
||||
else if (*result == 0 && *error == false)
|
||||
execute(expr->astOperand2(), programMemory, result, error);
|
||||
}
|
||||
|
||||
|
|
|
@ -140,6 +140,7 @@ private:
|
|||
TEST_CASE(valueFlowCrashConstructorInitialization);
|
||||
|
||||
TEST_CASE(valueFlowUnknownMixedOperators);
|
||||
TEST_CASE(valueFlowIdempotent);
|
||||
}
|
||||
|
||||
static bool isNotTokValue(const ValueFlow::Value &val) {
|
||||
|
@ -5014,6 +5015,42 @@ private:
|
|||
|
||||
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 1));
|
||||
}
|
||||
|
||||
void valueFlowIdempotent() {
|
||||
const char *code;
|
||||
|
||||
code = "void f(bool a, bool b) {\n"
|
||||
" bool x = true;\n"
|
||||
" if (a)\n"
|
||||
" x = x && b;\n"
|
||||
" bool result = x;\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(false, testValueOfXKnown(code, 5U, 1));
|
||||
|
||||
code = "void f(bool a, bool b) {\n"
|
||||
" bool x = false;\n"
|
||||
" if (a)\n"
|
||||
" x = x && b;\n"
|
||||
" bool result = x;\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(true, testValueOfXKnown(code, 5U, 0));
|
||||
|
||||
code = "void f(bool a, bool b) {\n"
|
||||
" bool x = true;\n"
|
||||
" if (a)\n"
|
||||
" x = x || b;\n"
|
||||
" bool result = x;\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(true, testValueOfXKnown(code, 5U, 1));
|
||||
|
||||
code = "void f(bool a, bool b) {\n"
|
||||
" bool x = false;\n"
|
||||
" if (a)\n"
|
||||
" x = x || b;\n"
|
||||
" bool result = x;\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(false, testValueOfXKnown(code, 5U, 0));
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestValueFlow)
|
||||
|
|
Loading…
Reference in New Issue