errmsg: added message about bad usage of char variable
This commit is contained in:
parent
ee54d4da91
commit
cc65242626
|
@ -737,9 +737,7 @@ void CheckOther::CheckCharVariable()
|
|||
std::string temp = "%var% [ " + tok->str() + " ]";
|
||||
if ((tok2->str() != ".") && Token::Match(tok2->next(), temp.c_str()))
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << _tokenizer->fileLine(tok2->next()) << ": Warning - using char variable as array index";
|
||||
_errorLogger->reportErr(errmsg.str());
|
||||
_errorLogger->reportErr(ErrorMessage::charArrayIndex(_tokenizer, tok2->next()));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -747,9 +745,7 @@ void CheckOther::CheckCharVariable()
|
|||
std::string tempSecond = tok->str() + " [&|]";
|
||||
if (Token::Match(tok2, tempFirst.c_str()) || Token::Match(tok2, tempSecond.c_str()))
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << _tokenizer->fileLine(tok2) << ": Warning - using char variable in bit operation";
|
||||
_errorLogger->reportErr(errmsg.str());
|
||||
_errorLogger->reportErr(ErrorMessage::charBitOp(_tokenizer, tok2));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,13 +244,10 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
if (ErrorMessage::udivWarning(_settings) || ErrorMessage::udivError(_settings))
|
||||
checkOther.CheckUnsignedDivision();
|
||||
|
||||
if (_settings._checkCodingStyle)
|
||||
{
|
||||
// Give warning when using char variable as array index
|
||||
// Give warning when using char variable as array index
|
||||
if (ErrorMessage::charArrayIndex(_settings) || ErrorMessage::charBitOp(_settings))
|
||||
checkOther.CheckCharVariable();
|
||||
|
||||
}
|
||||
|
||||
// Usage of local variables
|
||||
if (ErrorMessage::unusedVariable(_settings))
|
||||
checkOther.functionVariableUsage();
|
||||
|
|
|
@ -282,5 +282,23 @@ public:
|
|||
return s._checkCodingStyle;
|
||||
}
|
||||
|
||||
static std::string charArrayIndex(const Tokenizer *tokenizer, const Token *Location)
|
||||
{
|
||||
return msg1(tokenizer, Location) + "Warning - using char variable as array index";
|
||||
}
|
||||
static bool charArrayIndex(const Settings &s)
|
||||
{
|
||||
return s._checkCodingStyle;
|
||||
}
|
||||
|
||||
static std::string charBitOp(const Tokenizer *tokenizer, const Token *Location)
|
||||
{
|
||||
return msg1(tokenizer, Location) + "Warning - using char variable in bit operation";
|
||||
}
|
||||
static bool charBitOp(const Settings &s)
|
||||
{
|
||||
return s._checkCodingStyle;
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -90,6 +90,8 @@ int main()
|
|||
err.push_back(Message("unreadVariable", Message::STYLE, "Variable '%1' is assigned a value that is never used", "varname"));
|
||||
err.push_back(Message("unassignedVariable", Message::STYLE, "Variable '%1' is not assigned a value", "varname"));
|
||||
err.push_back(Message("constStatement", Message::STYLE, "Redundant code: Found a statement that begins with %1 constant", "type"));
|
||||
err.push_back(Message("charArrayIndex", Message::STYLE, "Warning - using char variable as array index"));
|
||||
err.push_back(Message("charBitOp", Message::STYLE, "Warning - using char variable in bit operation"));
|
||||
|
||||
// Generate code..
|
||||
std::cout << "Generate code.." << std::endl;
|
||||
|
|
Loading…
Reference in New Issue