Fixed #4929 (false positive: Division by zero (standard function div()))
This commit is contained in:
parent
5c4c397372
commit
027e5cc860
|
@ -2142,9 +2142,9 @@ void CheckOther::checkZeroDivision()
|
|||
MathLib::isInt(tok->next()->str()) &&
|
||||
MathLib::toLongNumber(tok->next()->str()) == 0L) {
|
||||
zerodivError(tok);
|
||||
} else if (Token::Match(tok, "div|ldiv|lldiv|imaxdiv ( %num% , %num% )") &&
|
||||
MathLib::isInt(tok->strAt(4)) &&
|
||||
MathLib::toLongNumber(tok->strAt(4)) == 0L) {
|
||||
} else if (Token::Match(tok, "std :: div|ldiv|lldiv|imaxdiv ( %num% , %num% )") &&
|
||||
MathLib::isInt(tok->strAt(6)) &&
|
||||
MathLib::toLongNumber(tok->strAt(6)) == 0L) {
|
||||
zerodivError(tok);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -336,9 +336,26 @@ private:
|
|||
void zeroDiv3() {
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" div_t divresult = div (1,0);\n"
|
||||
" div_t divresult = std::div (1,0);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str());
|
||||
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" div_t divresult = std::div (1,0L);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str());
|
||||
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" div_t divresult = std::div (1,0x5);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f() {\n" // #4929 - we don't know if this "div" is the standard function
|
||||
" div (1,0);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void zeroDiv4() {
|
||||
|
@ -366,18 +383,6 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str());
|
||||
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" div_t divresult = div (1,0L);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str());
|
||||
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" div_t divresult = div (1,0x5);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Don't warn about floating points (gcc doesn't warn either)
|
||||
// and floating points are handled differently than integers.
|
||||
check("void f()\n"
|
||||
|
|
Loading…
Reference in New Issue