diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 58ca6362c..cd6862a0c 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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, "std :: div|ldiv|lldiv|imaxdiv ( %num% , %num% )") && - MathLib::isInt(tok->strAt(6)) && - MathLib::toLongNumber(tok->strAt(6)) == 0L) { + } else if (Token::Match(tok, "div|ldiv|lldiv|imaxdiv ( %num% , %num% )") && + MathLib::isInt(tok->strAt(4)) && + MathLib::toLongNumber(tok->strAt(4)) == 0L) { zerodivError(tok); } } diff --git a/test/testother.cpp b/test/testother.cpp index 8512ffd52..0a82c6567 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -336,26 +336,9 @@ private: void zeroDiv3() { check("void f()\n" "{\n" - " div_t divresult = std::div (1,0);\n" + " div_t divresult = 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() { @@ -383,6 +366,18 @@ 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"