ValueFlow: Handle division by zero better in abstract interpretation
This commit is contained in:
parent
1be7bfa7fe
commit
c14a3d67bb
|
@ -679,6 +679,8 @@ static void execute(const Token *expr,
|
||||||
*result = result1 - result2;
|
*result = result1 - result2;
|
||||||
else if (expr->str() == "*")
|
else if (expr->str() == "*")
|
||||||
*result = result1 * result2;
|
*result = result1 * result2;
|
||||||
|
else if (result2 == 0)
|
||||||
|
*error = true;
|
||||||
else if (expr->str() == "/")
|
else if (expr->str() == "/")
|
||||||
*result = result1 / result2;
|
*result = result1 / result2;
|
||||||
else if (expr->str() == "%")
|
else if (expr->str() == "%")
|
||||||
|
|
|
@ -641,6 +641,12 @@ private:
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 3U, 8));
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 8));
|
||||||
ASSERT_EQUALS(false, testValueOfX(code, 3U, 10));
|
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"
|
code = "void f() {\n"
|
||||||
" for (int x = 0; x < 10; x++)\n"
|
" for (int x = 0; x < 10; x++)\n"
|
||||||
" x<4 ?\n"
|
" x<4 ?\n"
|
||||||
|
|
Loading…
Reference in New Issue