ValueFlow: Improved abstract interpretation

This commit is contained in:
Daniel Marjamäki 2014-03-24 06:48:06 +01:00
parent 591209ffac
commit aa05bf0f16
2 changed files with 12 additions and 8 deletions

View File

@ -688,16 +688,19 @@ static void execute(const Token *expr,
} }
else if (expr->str() == "&&") { else if (expr->str() == "&&") {
execute(expr->astOperand1(), programMemory, result, error); bool error1 = false;
if (*error || *result == 0) execute(expr->astOperand1(), programMemory, result, &error1);
if (!error1 && *result == 0)
*result = 0; *result = 0;
else { else {
execute(expr->astOperand2(), programMemory, result, error); bool error2 = false;
// If there is an error, assume the result is not important execute(expr->astOperand2(), programMemory, result, &error2);
if (*error) { if (error1 && error2)
*error = false; *error = true;
if (error2)
*result = 1; *result = 1;
} else
*result = !!*result;
} }
} }

View File

@ -1846,7 +1846,8 @@ private:
" data[x] = 0;\n" " data[x] = 0;\n"
" }" " }"
"}"); "}");
ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: data\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: data\n"
"[test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n", errout.str());
} }
void array_index_for_continue() { void array_index_for_continue() {