48 logChecker(
"CheckAssert::assertWithSideEffects");
55 for (
const Token* tmp = tok->
next(); tmp != endTok; tmp = tmp->
next()) {
63 if (f->isconst || f->ispure)
67 if (std::any_of(f->argumentChecks.begin(), f->argumentChecks.end(), [](
const std::pair<int, Library::ArgumentChecks>& ac) {
68 return ac.second.iteratorInfo.container > 0;
95 const Variable* var = tok2->previous()->variable();
101 bool noReturnInScope =
true;
103 if (rt->str() !=
"return")
continue;
105 noReturnInScope =
false;
109 if (noReturnInScope)
continue;
124 "assertWithSideEffect",
125 "$symbol:" + functionName +
"\n"
126 "Assert statement calls a function which may have desired side effects: '$symbol'.\n"
127 "Non-pure function: '$symbol' is called inside assert statement. "
128 "Assert statements are removed from release builds so the code inside "
129 "assert statement is not executed. If the code is needed also in release "
136 "assignmentInAssert",
137 "$symbol:" + varname +
"\n"
138 "Assert statement modifies '$symbol'.\n"
139 "Variable '$symbol' is modified inside assert statement. "
140 "Assert statements are removed from release builds so the code inside "
141 "assert statement is not executed. If the code is needed also in release "
156 if (assertionScope != var->
scope()) {
158 while (s && s != assertionScope)
160 if (s == assertionScope)
177 return returnTok->
scope() == assignTok->
scope();
bool astIsSmartPointer(const Token *tok)
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.
static Library::Container::Yield getContainerYield(const Token *const cond)
const Function * getFunction(const Token *ftok) const
std::string getFunctionName(const Token *ftok) const
Get function name for function call.
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.