Merge branch 'master' of github.com:danmar/cppcheck

This commit is contained in:
Robert Reif 2011-09-10 10:14:49 -04:00
commit 794fdd056b
2 changed files with 11 additions and 2 deletions

View File

@ -1870,8 +1870,7 @@ void CheckOther::checkZeroDivision()
{ {
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) 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::isInt(tok->next()->str()) &&
MathLib::toLongNumber(tok->next()->str()) == 0L) MathLib::toLongNumber(tok->next()->str()) == 0L)
{ {

View File

@ -42,6 +42,7 @@ private:
TEST_CASE(zeroDiv3); TEST_CASE(zeroDiv3);
TEST_CASE(zeroDiv4); TEST_CASE(zeroDiv4);
TEST_CASE(zeroDiv5); TEST_CASE(zeroDiv5);
TEST_CASE(zeroDiv6);
TEST_CASE(sprintf1); // Dangerous usage of sprintf TEST_CASE(sprintf1); // Dangerous usage of sprintf
TEST_CASE(sprintf2); TEST_CASE(sprintf2);
@ -367,6 +368,15 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero\n", errout.str()); 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[]) void sprintfUsage(const char code[])
{ {