Fixed #4929 (false positive: Division by zero (standard function div()))
This commit is contained in:
parent
c5723ab46a
commit
973bdcc6d8
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue