Fixed #3472 (false positive: (error) Passing value 0 to log() leads to undefined result)

This commit is contained in:
Daniel Marjamäki 2012-01-08 12:07:25 +01:00
parent ee55d3294a
commit 65ce55e675
2 changed files with 57 additions and 46 deletions

View File

@ -2160,7 +2160,14 @@ void CheckOther::zerodivError(const Token *tok)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::checkMathFunctions() void CheckOther::checkMathFunctions()
{ {
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { const SymbolDatabase *db = _tokenizer->getSymbolDatabase();
std::list<Scope>::const_iterator scope;
for (scope = db->scopeList.begin(); scope != db->scopeList.end(); ++scope) {
if (scope->type != Scope::eFunction)
continue;
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
if (tok->varId() == 0 && Token::Match(tok, "log|log10 ( %num% )")) { if (tok->varId() == 0 && Token::Match(tok, "log|log10 ( %num% )")) {
bool isNegative = MathLib::isNegative(tok->strAt(2)); bool isNegative = MathLib::isNegative(tok->strAt(2));
bool isInt = MathLib::isInt(tok->strAt(2)); bool isInt = MathLib::isInt(tok->strAt(2));
@ -2209,6 +2216,7 @@ void CheckOther::checkMathFunctions()
mathfunctionCallError(tok, 2); mathfunctionCallError(tok, 2);
} }
} }
}
} }
void CheckOther::mathfunctionCallError(const Token *tok, const unsigned int numParam) void CheckOther::mathfunctionCallError(const Token *tok, const unsigned int numParam)

View File

@ -929,6 +929,9 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #3473 - no warning if "log" is a variable
check("Fred::Fred() : log(0) { }");
ASSERT_EQUALS("", errout.str());
// acos // acos
check("void foo()\n" check("void foo()\n"