errmsg: Added 'assignment in if-condition'
This commit is contained in:
parent
aa592387e6
commit
c8a5bd16a1
|
@ -21,7 +21,6 @@
|
|||
#include "checkfunctionusage.h"
|
||||
#include "errormessage.h"
|
||||
#include "tokenize.h"
|
||||
#include <sstream>
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
|
|
@ -377,9 +377,7 @@ void CheckOther::CheckIfAssignment()
|
|||
Token::Match(tok, "if ( %var% = %str% )") ||
|
||||
Token::Match(tok, "if ( %var% = %var% )"))
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << _tokenizer->fileLine(tok) << ": Possible bug. Should it be '==' instead of '='?";
|
||||
_errorLogger->reportErr(ostr.str());
|
||||
_errorLogger->reportErr(ErrorMessage::ifAssignment(_tokenizer, tok));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -280,12 +280,9 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
if (ErrorMessage::arrayIndexOutOfBounds(_settings) && ErrorMessage::bufferOverrun(_settings))
|
||||
checkBufferOverrun.bufferOverrun();
|
||||
|
||||
if (_settings._showAll)
|
||||
{
|
||||
|
||||
// Check for "if (a=b)"
|
||||
if (ErrorMessage::ifAssignment(_settings))
|
||||
checkOther.CheckIfAssignment();
|
||||
}
|
||||
|
||||
// Dangerous functions, such as 'gets' and 'scanf'
|
||||
checkBufferOverrun.dangerousFunctions();
|
||||
|
|
|
@ -309,5 +309,14 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
static std::string ifAssignment(const Tokenizer *tokenizer, const Token *Location)
|
||||
{
|
||||
return msg1(tokenizer, Location) + "Assignment in if-condition";
|
||||
}
|
||||
static bool ifAssignment(const Settings &s)
|
||||
{
|
||||
return s._checkCodingStyle;
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -92,6 +92,7 @@ int main()
|
|||
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"));
|
||||
err.push_back(Message("variableScope", Message::never, "The scope of the variable %1 can be limited", "varname"));
|
||||
err.push_back(Message("ifAssignment", Message::style, "Assignment in if-condition"));
|
||||
|
||||
// Generate code..
|
||||
std::cout << "Generate code.." << std::endl;
|
||||
|
|
Loading…
Reference in New Issue