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() == "&&") {
execute(expr->astOperand1(), programMemory, result, error);
if (*error || *result == 0)
bool error1 = false;
execute(expr->astOperand1(), programMemory, result, &error1);
if (!error1 && *result == 0)
*result = 0;
else {
execute(expr->astOperand2(), programMemory, result, error);
// If there is an error, assume the result is not important
if (*error) {
*error = false;
bool error2 = false;
execute(expr->astOperand2(), programMemory, result, &error2);
if (error1 && error2)
*error = true;
if (error2)
*result = 1;
}
else
*result = !!*result;
}
}

View File

@ -1846,7 +1846,8 @@ private:
" 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() {