buffer overruns : renamed functions + minor simplification

This commit is contained in:
Daniel Marjamäki 2008-12-20 08:53:42 +00:00
parent 6b06df766b
commit 7301709699
4 changed files with 9 additions and 16 deletions

View File

@ -520,7 +520,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable()
void CheckBufferOverrunClass::CheckBufferOverrun()
void CheckBufferOverrunClass::bufferOverrun()
{
CheckBufferOverrun_LocalVariable();
CheckBufferOverrun_StructVariable();
@ -538,21 +538,14 @@ void CheckBufferOverrunClass::CheckBufferOverrun()
// Dangerous functions
//---------------------------------------------------------------------------
void CheckBufferOverrunClass::WarningDangerousFunctions()
void CheckBufferOverrunClass::dangerousFunctions()
{
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
if (TOKEN::Match(tok, "gets ("))
if (TOKEN::Match(tok, "gets|scanf ("))
{
std::ostringstream ostr;
ostr << _tokenizer->fileLine(tok) << ": Found 'gets'. You should use 'fgets' instead";
_errorLogger->reportErr(ostr.str());
}
else if (TOKEN::Match(tok, "scanf (") && strcmp(tok->strAt(2),"\"%s\"") == 0)
{
std::ostringstream ostr;
ostr << _tokenizer->fileLine(tok) << ": Found 'scanf'. You should use 'fgets' instead";
ostr << _tokenizer->fileLine(tok) << ": Found '" << tok->str() << "'. You should use 'fgets' instead";
_errorLogger->reportErr(ostr.str());
}
}

View File

@ -32,11 +32,11 @@ public:
~CheckBufferOverrunClass();
// Buffer overrun..
void CheckBufferOverrun();
void bufferOverrun();
// Dangerous functions that can cause buffer overruns
void WarningDangerousFunctions();
void dangerousFunctions();
private:
void CheckBufferOverrun_StructVariable();
void CheckBufferOverrun_LocalVariable();

View File

@ -246,7 +246,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
// Buffer overruns..
CheckBufferOverrunClass checkBufferOverrun( &_tokenizer, _settings, this );
checkBufferOverrun.CheckBufferOverrun();
checkBufferOverrun.bufferOverrun();
// Check that all class constructors are ok.
checkClass.constructors();
@ -271,7 +271,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
// Dangerous functions, such as 'gets' and 'scanf'
checkBufferOverrun.WarningDangerousFunctions();
checkBufferOverrun.dangerousFunctions();
// Invalid function usage..

View File

@ -57,7 +57,7 @@ private:
Settings settings;
settings._showAll = true;
CheckBufferOverrunClass checkBufferOverrun( &tokenizer, settings, this );
checkBufferOverrun.CheckBufferOverrun();
checkBufferOverrun.bufferOverrun();
}
void run()