ValueFlow: Handle division by zero better in abstract interpretation

This commit is contained in:
Daniel Marjamäki 2014-03-23 20:37:56 +01:00
parent 1be7bfa7fe
commit c14a3d67bb
2 changed files with 8 additions and 0 deletions

View File

@ -679,6 +679,8 @@ static void execute(const Token *expr,
*result = result1 - result2;
else if (expr->str() == "*")
*result = result1 * result2;
else if (result2 == 0)
*error = true;
else if (expr->str() == "/")
*result = result1 / result2;
else if (expr->str() == "%")

View File

@ -641,6 +641,12 @@ private:
ASSERT_EQUALS(true, testValueOfX(code, 3U, 8));
ASSERT_EQUALS(false, testValueOfX(code, 3U, 10));
code = "void f() {\n"
" for (int x = 0; x < 10; x = x / 0)\n"
" a[x] = 0;\n"
"}";
testValueOfX(code, 3U, 0); // don't crash
code = "void f() {\n"
" for (int x = 0; x < 10; x++)\n"
" x<4 ?\n"