Fixed #4929 (false positive: Division by zero (standard function div()))

This commit is contained in:
Daniel Marjamäki 2013-09-29 11:13:49 +02:00
parent c5723ab46a
commit 973bdcc6d8
2 changed files with 13 additions and 0 deletions

View File

@ -2145,6 +2145,12 @@ void CheckOther::checkZeroDivision()
} else if (Token::Match(tok, "div|ldiv|lldiv|imaxdiv ( %num% , %num% )") &&
MathLib::isInt(tok->strAt(4)) &&
MathLib::toLongNumber(tok->strAt(4)) == 0L) {
if (tok->str() == "div") {
if (tok->strAt(-1) == ".")
continue;
if (tok->variable() || tok->function())
continue;
}
zerodivError(tok);
}
}

View File

@ -341,6 +341,13 @@ private:
" div_t divresult = div (1,0);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str());
// #4929 - if there is a user function with the name "div" don't warn
check("void div(int a, int b);\n"
"void f() {\n"
" div (1,0);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void zeroDiv4() {