diff --git a/lib/checkother.cpp b/lib/checkother.cpp index b684a0c0f..fbf46509e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1870,8 +1870,7 @@ void CheckOther::checkZeroDivision() { for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { - - if (Token::Match(tok, "/ %num%") && + if (Token::Match(tok, "[/%] %num%") && MathLib::isInt(tok->next()->str()) && MathLib::toLongNumber(tok->next()->str()) == 0L) { diff --git a/test/testother.cpp b/test/testother.cpp index 559734f79..916b47e95 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -42,6 +42,7 @@ private: TEST_CASE(zeroDiv3); TEST_CASE(zeroDiv4); TEST_CASE(zeroDiv5); + TEST_CASE(zeroDiv6); TEST_CASE(sprintf1); // Dangerous usage of sprintf TEST_CASE(sprintf2); @@ -367,6 +368,15 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero\n", errout.str()); } + void zeroDiv6() + { + check("void f()\n" + "{ { {\n" + " int a = b % 0;\n" + "} } }\n"); + ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero\n", errout.str()); + } + void sprintfUsage(const char code[]) {