astyle changes, missed from previous commits
This commit is contained in:
parent
66547e7ddf
commit
42b661630b
|
@ -59,7 +59,7 @@ void CheckOther::WarningOldStylePointerCast()
|
|||
if (!Token::findmatch(_tokenizer->tokens(), pattern.c_str()))
|
||||
continue;
|
||||
|
||||
_errorLogger->reportErr( ErrorMessage::cstyleCast(_tokenizer, tok) );
|
||||
_errorLogger->reportErr(ErrorMessage::cstyleCast(_tokenizer, tok));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ void CheckOther::WarningRedundantCode()
|
|||
|
||||
if (err)
|
||||
{
|
||||
_errorLogger->reportErr( ErrorMessage::redundantIfDelete0(_tokenizer, tok) );
|
||||
_errorLogger->reportErr(ErrorMessage::redundantIfDelete0(_tokenizer, tok));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ void CheckOther::redundantCondition2()
|
|||
var2->str() == var3->str() &&
|
||||
any1->str() == any2->str())
|
||||
{
|
||||
_errorLogger->reportErr( ErrorMessage::redundantIfRemove(_tokenizer, tok) );
|
||||
_errorLogger->reportErr(ErrorMessage::redundantIfRemove(_tokenizer, tok));
|
||||
}
|
||||
|
||||
tok = Token::findmatch(tok->next(), pattern);
|
||||
|
@ -331,33 +331,33 @@ void CheckOther::InvalidFunctionUsage()
|
|||
// Get variable id of target buffer..
|
||||
unsigned int varid = 0;
|
||||
|
||||
if ( Token::Match(tok, "sprintf|snprintf ( %var% ,") )
|
||||
if (Token::Match(tok, "sprintf|snprintf ( %var% ,"))
|
||||
varid = tok->tokAt(2)->varId();
|
||||
|
||||
else if ( Token::Match(tok, "sprintf|snprintf ( %var% . %var% ,") )
|
||||
else if (Token::Match(tok, "sprintf|snprintf ( %var% . %var% ,"))
|
||||
varid = tok->tokAt(4)->varId();
|
||||
|
||||
if ( varid == 0 )
|
||||
if (varid == 0)
|
||||
continue;
|
||||
|
||||
// goto ","
|
||||
const Token *tok2 = tok->tokAt(3);
|
||||
while ( tok2 && tok2->str() != "," )
|
||||
while (tok2 && tok2->str() != ",")
|
||||
tok2 = tok2->next();
|
||||
|
||||
// is any source buffer overlapping the target buffer?
|
||||
unsigned int parlevel = 0;
|
||||
while ( (tok2 = tok2->next()) != NULL )
|
||||
while ((tok2 = tok2->next()) != NULL)
|
||||
{
|
||||
if ( tok2->str() == "(" )
|
||||
if (tok2->str() == "(")
|
||||
++parlevel;
|
||||
else if ( tok2->str() == ")" )
|
||||
else if (tok2->str() == ")")
|
||||
{
|
||||
--parlevel;
|
||||
if ( parlevel < 0 )
|
||||
if (parlevel < 0)
|
||||
break;
|
||||
}
|
||||
else if ( tok2->varId() == varid )
|
||||
else if (tok2->varId() == varid)
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << _tokenizer->fileLine(tok2) << ": Overlapping data buffer " << tok2->str();
|
||||
|
|
|
@ -273,7 +273,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
|
||||
// Memory leak
|
||||
CheckMemoryLeakClass checkMemoryLeak(&_tokenizer, _settings, this);
|
||||
if ( ErrorMessage::memleak(_settings) )
|
||||
if (ErrorMessage::memleak(_settings))
|
||||
checkMemoryLeak.CheckMemoryLeak();
|
||||
|
||||
// Check that all class constructors are ok.
|
||||
|
@ -310,7 +310,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
|
||||
|
||||
// Warning upon c-style pointer casts
|
||||
if ( ErrorMessage::cstyleCast(_settings) )
|
||||
if (ErrorMessage::cstyleCast(_settings))
|
||||
{
|
||||
const char *ext = strrchr(FileName, '.');
|
||||
if (ext && strcmp(ext, ".cpp") == 0)
|
||||
|
@ -318,7 +318,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
}
|
||||
|
||||
// if (a) delete a;
|
||||
if ( ErrorMessage::redundantIfDelete0(_settings) )
|
||||
if (ErrorMessage::redundantIfDelete0(_settings))
|
||||
checkOther.WarningRedundantCode();
|
||||
|
||||
|
||||
|
|
|
@ -31,29 +31,49 @@ private:
|
|||
static std::string msg1(const Tokenizer *tokenizer, const Token *Location);
|
||||
public:
|
||||
static std::string memleak(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
||||
{ return msg1(tokenizer, Location) + "Memory leak: " + varname + ""; }
|
||||
{
|
||||
return msg1(tokenizer, Location) + "Memory leak: " + varname + "";
|
||||
}
|
||||
static bool memleak(const Settings &s)
|
||||
{ return true; }
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string resourceLeak(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
|
||||
{ return msg1(tokenizer, Location) + "Resource leak: " + varname + ""; }
|
||||
{
|
||||
return msg1(tokenizer, Location) + "Resource leak: " + varname + "";
|
||||
}
|
||||
static bool resourceLeak(const Settings &s)
|
||||
{ return true; }
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string cstyleCast(const Tokenizer *tokenizer, const Token *Location)
|
||||
{ return msg1(tokenizer, Location) + "C-style pointer casting"; }
|
||||
{
|
||||
return msg1(tokenizer, Location) + "C-style pointer casting";
|
||||
}
|
||||
static bool cstyleCast(const Settings &s)
|
||||
{ return & s._checkCodingStyle; }
|
||||
{
|
||||
return & s._checkCodingStyle;
|
||||
}
|
||||
|
||||
static std::string redundantIfDelete0(const Tokenizer *tokenizer, const Token *Location)
|
||||
{ return msg1(tokenizer, Location) + "Redundant condition. It is safe to deallocate a NULL pointer"; }
|
||||
{
|
||||
return msg1(tokenizer, Location) + "Redundant condition. It is safe to deallocate a NULL pointer";
|
||||
}
|
||||
static bool redundantIfDelete0(const Settings &s)
|
||||
{ return & s._checkCodingStyle; }
|
||||
{
|
||||
return & s._checkCodingStyle;
|
||||
}
|
||||
|
||||
static std::string redundantIfRemove(const Tokenizer *tokenizer, const Token *Location)
|
||||
{ return msg1(tokenizer, Location) + "Redundant condition. The remove function in the STL will not do anything if element doesn't exist"; }
|
||||
{
|
||||
return msg1(tokenizer, Location) + "Redundant condition. The remove function in the STL will not do anything if element doesn't exist";
|
||||
}
|
||||
static bool redundantIfRemove(const Settings &s)
|
||||
{ return & s._checkCodingStyle; }
|
||||
{
|
||||
return & s._checkCodingStyle;
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -107,11 +107,11 @@ private:
|
|||
|
||||
void sprintf1()
|
||||
{
|
||||
sprintfUsage( "void foo()\n"
|
||||
"{\n"
|
||||
" char buf[100];\n"
|
||||
" sprintf(buf,\"%s\",buf);\n"
|
||||
"}\n");
|
||||
sprintfUsage("void foo()\n"
|
||||
"{\n"
|
||||
" char buf[100];\n"
|
||||
" sprintf(buf,\"%s\",buf);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(std::string("[test.cpp:4]: Overlapping data buffer buf\n"), errout.str());
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue