47 logChecker(
"CheckAssert::assertWithSideEffects");
54 for (
const Token* tmp = tok->
next(); tmp != endTok; tmp = tmp->
next()) {
76 const Variable* var = tok2->previous()->variable();
82 bool noReturnInScope =
true;
84 if (rt->str() !=
"return")
continue;
86 noReturnInScope =
false;
90 if (noReturnInScope)
continue;
105 "assertWithSideEffect",
106 "$symbol:" + functionName +
"\n"
107 "Assert statement calls a function which may have desired side effects: '$symbol'.\n"
108 "Non-pure function: '$symbol' is called inside assert statement. "
109 "Assert statements are removed from release builds so the code inside "
110 "assert statement is not executed. If the code is needed also in release "
117 "assignmentInAssert",
118 "$symbol:" + varname +
"\n"
119 "Assert statement modifies '$symbol'.\n"
120 "Variable '$symbol' is modified inside assert statement. "
121 "Assert statements are removed from release builds so the code inside "
122 "assert statement is not executed. If the code is needed also in release "
137 if (assertionScope != var->
scope()) {
139 while (s && s != assertionScope)
141 if (s == assertionScope)
158 return returnTok->
scope() == assignTok->
scope();
static const CWE CWE398(398U)
Checking for side effects in assert statements.
void assertWithSideEffects()
void assignmentInAssertError(const Token *tok, const std::string &varname)
void sideEffectInAssertError(const Token *tok, const std::string &functionName)
static bool inSameScope(const Token *returnTok, const Token *assignTok)
void checkVariableAssignment(const Token *assignTok, const Scope *assertionScope)
void reportError(const Token *tok, const Severity severity, const std::string &id, const std::string &msg)
report an error
const Settings *const mSettings
const Tokenizer *const mTokenizer
void logChecker(const char id[])
log checker
const std::string & name() const
const Scope * functionScope
scope of function body
const Scope * nestedIn
Scope the function is declared in.
const Token * bodyStart
'{' token
const Token * bodyEnd
'}' token
bool isClassOrStruct() const
SimpleEnableGroup< Severity > severity
bool isEnabled(T flag) const
const Token * front() const
get first token of list
The token list that the TokenList generates is a linked-list of this class.
void astOperand1(Token *tok)
Token::Type tokType() const
void scope(const Scope *s)
Associate this token with given scope.
void link(Token *linkToToken)
Create link to given token.
bool isAssignmentOp() const
static bool simpleMatch(const Token *tok, const char(&pattern)[count])
Match given token (or list of tokens) to a pattern list.
TokenList list
Token list: stores all tokens.
Information about a member variable.
bool isArgument() const
Is variable a function argument.
bool isReference() const
Is reference variable.
bool isLocal() const
Is variable local.
const Scope * scope() const
Get Scope pointer of enclosing scope.
const std::string & name() const
Get name string.
bool isConst() const
Is variable const.
bool isPointer() const
Is pointer variable.