Fixed #5965 (False positive zerodiv - loop iterating over double variable)

This commit is contained in:
Daniel Marjamäki 2014-07-17 08:44:55 +02:00
parent d3425d5c61
commit 15bb447fdc
2 changed files with 11 additions and 1 deletions

View File

@ -943,8 +943,11 @@ static void execute(const Token *expr,
if (!expr)
*error = true;
else if (expr->isNumber())
else if (expr->isNumber()) {
*result = MathLib::toLongNumber(expr->str());
if (MathLib::isFloat(expr->str()))
*error = true;
}
else if (expr->varId() > 0) {
const std::map<unsigned int, MathLib::bigint>::const_iterator var = programMemory->find(expr->varId());

View File

@ -939,6 +939,13 @@ private:
" x;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 4U, 0));
code = "void foo(double recoveredX) {\n"
" for (double x = 1e-18; x < 1e40; x *= 1.9) {\n"
" double relativeError = (x - recoveredX) / x;\n"
" }\n"
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
}
void valueFlowSubFunction() {