Refactor and rename CHECK_WRONG_DATA
This commit is contained in:
parent
fc79941828
commit
150d2aa902
|
@ -41,6 +41,19 @@ void Check::reportError(const ErrorLogger::ErrorMessage &errmsg)
|
|||
std::cout << errmsg.toXML(true, 1) << std::endl;
|
||||
}
|
||||
|
||||
bool Check::wrongData(const Token *tok, bool condition, const char *str)
|
||||
{
|
||||
#if defined(DACA2) || defined(UNSTABLE)
|
||||
if (condition) {
|
||||
reportError(tok, Severity::debug, "DacaWrongData", "Wrong data detected by condition " + std::string(str));
|
||||
}
|
||||
#else
|
||||
(void)tok;
|
||||
(void)str;
|
||||
#endif
|
||||
return condition;
|
||||
}
|
||||
|
||||
std::list<Check *> &Check::instances()
|
||||
{
|
||||
#ifdef __SVR4
|
||||
|
|
20
lib/check.h
20
lib/check.h
|
@ -31,22 +31,13 @@
|
|||
#include <list>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* When -DDACA2 is used, Cppcheck will print error messages when wrong
|
||||
* data is seen. Intended to be used in Daca2
|
||||
*
|
||||
* Use CHECK_WRONG_DATA in checkers when you check for wrong data.
|
||||
*/
|
||||
#if defined(DACA2) || defined(UNSTABLE)
|
||||
#define CHECK_WRONG_DATA(COND, TOK) ({ if(!(COND)) reportError(TOK,Severity::debug,"DacaWrongData","Wrong data detected, " #COND); (COND);})
|
||||
#else
|
||||
#define CHECK_WRONG_DATA(COND, TOK) (COND)
|
||||
#endif
|
||||
|
||||
namespace tinyxml2 {
|
||||
class XMLElement;
|
||||
}
|
||||
|
||||
/** Use WRONG_DATA in checkers to mark conditions that check that data is correct */
|
||||
#define WRONG_DATA(COND, TOK) (wrongData((TOK), (COND), #COND))
|
||||
|
||||
/// @addtogroup Core
|
||||
/// @{
|
||||
|
||||
|
@ -187,6 +178,11 @@ protected:
|
|||
return errorPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use WRONG_DATA in checkers when you check for wrong data. That
|
||||
* will call this method
|
||||
*/
|
||||
bool wrongData(const Token *tok, bool condition, const char *str);
|
||||
private:
|
||||
const std::string _name;
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ void CheckFunctions::checkIgnoredReturnValue()
|
|||
continue;
|
||||
}
|
||||
|
||||
if ((!tok->function() || !Token::Match(tok->function()->retDef, "void %name%")) && _settings->library.isUseRetVal(tok) && CHECK_WRONG_DATA(tok->next()->astOperand1(), tok))
|
||||
if ((!tok->function() || !Token::Match(tok->function()->retDef, "void %name%")) && _settings->library.isUseRetVal(tok) && !WRONG_DATA(tok->next()->astOperand1(), tok))
|
||||
ignoredReturnValueError(tok, tok->next()->astOperand1()->expressionString());
|
||||
}
|
||||
}
|
||||
|
@ -323,7 +323,7 @@ void CheckFunctions::memsetZeroBytes()
|
|||
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||
if (Token::Match(tok, "memset|wmemset (") && (numberOfArguments(tok)==3)) {
|
||||
const std::vector<const Token *> &arguments = getArguments(tok);
|
||||
if (!CHECK_WRONG_DATA(arguments.size() == 3U, tok))
|
||||
if (WRONG_DATA(arguments.size() == 3U, tok))
|
||||
continue;
|
||||
const Token* lastParamTok = arguments[2];
|
||||
if (lastParamTok->str() == "0")
|
||||
|
|
Loading…
Reference in New Issue