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

This commit is contained in:
Martin Ettl 2010-04-05 20:08:21 +02:00
commit f895ab9a0d
4 changed files with 51 additions and 13 deletions

View File

@ -2563,18 +2563,18 @@ void CheckOther::checkMathFunctions()
{
mathfunctionCallError(tok);
}
// atan2 ( x , y): x and y can not be zero, because this is mathematically not defined
// atan2 ( x , y): x and y can not be zero, because this is mathematically not defined
else if (Token::Match(tok, "atan2 ( %num% , %num% )") &&
MathLib::isNullValue(tok->tokAt(2)->str()) &&
MathLib::isNullValue(tok->tokAt(4)->str()))
MathLib::isNullValue(tok->tokAt(4)->str()))
{
mathfunctionCallError(tok,2);
mathfunctionCallError(tok, 2);
}
// fmod ( x , y) If y is zero, then either a range error will occur or the function will return zero (implementation-defined).
// fmod ( x , y) If y is zero, then either a range error will occur or the function will return zero (implementation-defined).
else if (Token::Match(tok, "fmod ( %num% , %num% )") &&
MathLib::isNullValue(tok->tokAt(4)->str()))
MathLib::isNullValue(tok->tokAt(4)->str()))
{
mathfunctionCallError(tok,2);
mathfunctionCallError(tok, 2);
}
// pow ( x , y) If x is zero, and y is negative --> division by zero
else if (Token::Match(tok, "pow ( %num% , %num% )") &&
@ -2735,11 +2735,11 @@ void CheckOther::mathfunctionCallError(const Token *tok, const unsigned int numP
{
if (tok)
{
if(numParam == 1)
reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->tokAt(2)->str() + " to " + tok->str() + "() leads to undefined result");
else if (numParam == 2)
reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->tokAt(2)->str() + " and " + tok->tokAt(4)->str() + " to " + tok->str() + "() leads to undefined result");
}
if (numParam == 1)
reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->tokAt(2)->str() + " to " + tok->str() + "() leads to undefined result");
else if (numParam == 2)
reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->tokAt(2)->str() + " and " + tok->tokAt(4)->str() + " to " + tok->str() + "() leads to undefined result");
}
else
reportError(tok, Severity::error, "wrongmathcall", "Passing value " " to " "() leads to undefined result");
}

View File

@ -189,7 +189,7 @@ public:
void uninitdataError(const Token *tok, const std::string &varname);
void uninitvarError(const Token *tok, const std::string &varname);
void zerodivError(const Token *tok);
void mathfunctionCallError(const Token *tok, const unsigned int numParam=1);
void mathfunctionCallError(const Token *tok, const unsigned int numParam = 1);
void postIncrementError(const Token *tok, const std::string &var_name, const bool isIncrement);
void getErrorMessages()

View File

@ -130,6 +130,8 @@ private:
TEST_CASE(strncat1);
TEST_CASE(strncat2);
TEST_CASE(memfunc); // memchr/memset/memcpy
TEST_CASE(cin1);
TEST_CASE(varid1);
@ -1432,6 +1434,42 @@ private:
// memchr/memset/memcpy/etc
void memfunc()
{
check("void f()\n"
"{\n"
" char str[5];\n"
" memset(str, 0, 10);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
check("void f()\n"
"{\n"
" char a[5], b[50];\n"
" memcpy(a, b, 10);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
check("void f()\n"
"{\n"
" char a[5], b[50];\n"
" memmove(a, b, 10);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
// When this TODO assertion works, ticket #909 can probably be closed
check("void f()\n"
"{\n"
" char a[5], b[50];\n"
" memchr(a, b, 10);\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
ASSERT_EQUALS("", errout.str());
}
void cin1()
{
check("#include <iostream>\n"