errormessage: added error message ErrorMessage::dangerousUsageStrtol
This commit is contained in:
parent
3e5398499f
commit
7851b1042f
|
@ -314,9 +314,7 @@ void CheckOther::InvalidFunctionUsage()
|
|||
int radix = atoi(tok2->strAt(1));
|
||||
if (!(radix == 0 || (radix >= 2 && radix <= 36)))
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << _tokenizer->fileLine(tok2) << ": Invalid radix in call to strtol or strtoul. Must be 0 or 2-36";
|
||||
_errorLogger->reportErr(ostr.str());
|
||||
_errorLogger->reportErr(ErrorMessage::dangerousUsageStrtol(_tokenizer, tok2));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -255,14 +255,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
checkOther.functionVariableUsage();
|
||||
}
|
||||
|
||||
// Including header which is not needed (too many false positives)
|
||||
// if ( _settings._checkCodingStyle )
|
||||
// {
|
||||
// CheckHeaders checkHeaders( &tokenizer );
|
||||
// checkHeaders.WarningIncludeHeader();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
_tokenizer.simplifyTokenList();
|
||||
|
||||
|
@ -291,26 +283,11 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
|
||||
// Check for "if (a=b)"
|
||||
checkOther.CheckIfAssignment();
|
||||
|
||||
// Check for case without break
|
||||
// Disabled because it generates many false positives
|
||||
// CheckCaseWithoutBreak();
|
||||
|
||||
// Dangerous usage of strtok
|
||||
// Disabled because it generates false positives
|
||||
//WarningStrTok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Dangerous functions, such as 'gets' and 'scanf'
|
||||
checkBufferOverrun.dangerousFunctions();
|
||||
|
||||
|
||||
// Invalid function usage..
|
||||
checkOther.InvalidFunctionUsage();
|
||||
|
||||
|
||||
// Warning upon c-style pointer casts
|
||||
if (ErrorMessage::cstyleCast(_settings))
|
||||
{
|
||||
|
@ -323,6 +300,9 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
if (ErrorMessage::redundantIfDelete0(_settings))
|
||||
checkOther.WarningRedundantCode();
|
||||
|
||||
// strtol and strtoul usage
|
||||
if (ErrorMessage::dangerousUsageStrtol(_settings))
|
||||
checkOther.InvalidFunctionUsage();
|
||||
|
||||
if (_settings._checkCodingStyle)
|
||||
{
|
||||
|
|
|
@ -75,5 +75,14 @@ public:
|
|||
return & s._checkCodingStyle;
|
||||
}
|
||||
|
||||
static std::string dangerousUsageStrtol(const Tokenizer *tokenizer, const Token *Location)
|
||||
{
|
||||
return msg1(tokenizer, Location) + "Invalid radix in call to strtol or strtoul. Must be 0 or 2-36";
|
||||
}
|
||||
static bool dangerousUsageStrtol(const Settings &s)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -58,6 +58,7 @@ int main()
|
|||
err.push_back(Message("cstyleCast", Message::STYLE, "C-style pointer casting", ""));
|
||||
err.push_back(Message("redundantIfDelete0", Message::STYLE, "Redundant condition. It is safe to deallocate a NULL pointer", ""));
|
||||
err.push_back(Message("redundantIfRemove", Message::STYLE, "Redundant condition. The remove function in the STL will not do anything if element doesn't exist", ""));
|
||||
err.push_back(Message("dangerousUsageStrtol", 0, "Invalid radix in call to strtol or strtoul. Must be 0 or 2-36", ""));
|
||||
|
||||
// Generate code..
|
||||
std::cout << "Generate code.." << std::endl;
|
||||
|
|
Loading…
Reference in New Issue