added atan2() check to ticket #1513
This commit is contained in:
parent
618e0217cf
commit
d4923e2a92
|
@ -2562,6 +2562,13 @@ void CheckOther::checkMathFunctions()
|
|||
std::fabs(MathLib::toDoubleNumber(tok->tokAt(2)->str())) > 1.0)
|
||||
{
|
||||
mathfunctionCallError(tok);
|
||||
}
|
||||
// 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()))
|
||||
{
|
||||
mathfunctionCallError(tok,2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2710,10 +2717,15 @@ void CheckOther::zerodivError(const Token *tok)
|
|||
reportError(tok, Severity::error, "zerodiv", "Division by zero");
|
||||
}
|
||||
|
||||
void CheckOther::mathfunctionCallError(const Token *tok)
|
||||
void CheckOther::mathfunctionCallError(const Token *tok, const unsigned int numParam)
|
||||
{
|
||||
if (tok)
|
||||
reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->tokAt(2)->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");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
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()
|
||||
|
|
|
@ -300,6 +300,7 @@ bool MathLib::isGreater(const std::string &first, const std::string &second)
|
|||
bool MathLib::isNullValue(const std::string &str)
|
||||
{
|
||||
return (str == "-0" || str == "-0.0"
|
||||
|| str == "0"
|
||||
|| str == "-0." || str == "-0E-00"
|
||||
|| str == "-0E+00" || str == "+0E+00"
|
||||
|| str == "+0E-00" || str == "+0"
|
||||
|
|
|
@ -2281,6 +2281,32 @@ private:
|
|||
" std::cout << acos(-110) << std::endl;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Passing value -110 to acos() leads to undefined result\n", errout.str());
|
||||
|
||||
|
||||
// atan2
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
" std::cout << atan2(1,1) << std::endl;\n"
|
||||
" std::cout << atan2(-1,-1) << std::endl;\n"
|
||||
" std::cout << atan2(0.1,1) << std::endl;\n"
|
||||
" std::cout << atan2(0.0001,100) << std::endl;\n"
|
||||
" std::cout << atan2(0.01m-1) << std::endl;\n"
|
||||
" std::cout << atan2(1.0E-1,-3) << std::endl;\n"
|
||||
" std::cout << atan2(-1.0E-1,+2) << std::endl;\n"
|
||||
" std::cout << atan2(+1.0E-1,0) << std::endl;\n"
|
||||
" std::cout << atan2(0.1E-1,3) << std::endl;\n"
|
||||
" std::cout << atan2(+0.1E-1,1) << std::endl;\n"
|
||||
" std::cout << atan2(-0.1E-1,8) << std::endl;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
" std::cout << atan2(0,0) << std::endl;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 0 and 0 to atan2() leads to undefined result\n", errout.str());
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue