Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,7 @@ static bool isEscapedOrJump(const Token* tok, bool functionsScope, const Library
return Token::Match(tok, "return|goto|throw|continue|break");
}

bool isEscapeFunction(const Token* ftok, const Library* library)
bool isEscapeFunction(const Token* ftok, const Library& library)
{
if (!Token::Match(ftok, "%name% ("))
return false;
Expand All @@ -2181,8 +2181,8 @@ bool isEscapeFunction(const Token* ftok, const Library* library)
return true;
if (function->isAttributeNoreturn())
return true;
} else if (library) {
if (library->isnoreturn(ftok))
} else {
if (library.isnoreturn(ftok))
return true;
}
return false;
Expand Down Expand Up @@ -2840,7 +2840,7 @@ const Token* findExpression(const Token* start, const nonneg int exprid)
return nullptr;
}

const Token* findEscapeStatement(const Scope* scope, const Library* library)
const Token* findEscapeStatement(const Scope* scope, const Library& library)
{
if (!scope)
return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions lib/astutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const Token* findExpression(nonneg int exprid,
const Token* findExpression(const Token* start, nonneg int exprid);

/** Does code execution escape from the given scope? */
const Token* findEscapeStatement(const Scope* scope, const Library* library);
const Token* findEscapeStatement(const Scope* scope, const Library& library);

std::vector<const Token*> astFlatten(const Token* tok, const char* op);
std::vector<Token*> astFlatten(Token* tok, const char* op);
Expand Down Expand Up @@ -298,7 +298,7 @@ bool isWithoutSideEffects(const Token* tok, bool checkArrayAccess = false, bool

bool isUniqueExpression(const Token* tok);

bool isEscapeFunction(const Token* ftok, const Library* library);
bool isEscapeFunction(const Token* ftok, const Library& library);

/** Is scope a return scope (scope will unconditionally return) */
CPPCHECKLIB bool isReturnScope(const Token* endToken,
Expand Down
12 changes: 6 additions & 6 deletions lib/checkautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,9 @@ static int getPointerDepth(const Token *tok)
return n;
}

static bool isDeadTemporary(const Token* tok, const Token* expr, const Library* library)
static bool isDeadTemporary(const Token* tok, const Token* expr, const Library& library)
{
if (!isTemporary(tok, library))
if (!isTemporary(tok, &library))
return false;
if (expr) {
if (!precedes(nextAfterAstRightmostLeaf(tok->astTop()), nextAfterAstRightmostLeaf(expr->astTop())))
Expand Down Expand Up @@ -562,7 +562,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
errorReturnReference(tok, lt.errorPath, lt.inconclusive);
break;
}
if (isDeadTemporary(lt.token, nullptr, &mSettings->library)) {
if (isDeadTemporary(lt.token, nullptr, mSettings->library)) {
errorReturnTempReference(tok, lt.errorPath, lt.inconclusive);
break;
}
Expand All @@ -584,7 +584,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
if (!printInconclusive && lt.inconclusive)
continue;
const Token * tokvalue = lt.token;
if (isDeadTemporary(tokvalue, tok, &mSettings->library)) {
if (isDeadTemporary(tokvalue, tok, mSettings->library)) {
errorDanglingTempReference(tok, lt.errorPath, lt.inconclusive);
break;
}
Expand Down Expand Up @@ -614,15 +614,15 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
continue;
if ((tokvalue->variable() && !isEscapedReference(tokvalue->variable()) &&
isInScope(tokvalue->variable()->nameToken(), scope)) ||
isDeadTemporary(tokvalue, nullptr, &mSettings->library)) {
isDeadTemporary(tokvalue, nullptr, mSettings->library)) {
errorReturnDanglingLifetime(tok, &val);
break;
}
} else if (tokvalue->variable() && isDeadScope(tokvalue->variable()->nameToken(), tok->scope())) {
errorInvalidLifetime(tok, &val);
break;
} else if (!tokvalue->variable() &&
isDeadTemporary(tokvalue, tok, &mSettings->library)) {
isDeadTemporary(tokvalue, tok, mSettings->library)) {
if (!diag(tokvalue))
errorDanglingTemporaryLifetime(tok, &val, tokvalue);
break;
Expand Down
10 changes: 5 additions & 5 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,21 +1391,21 @@ void CheckOther::commaSeparatedReturnError(const Token *tok)
"macro is then used in a return statement, it is less likely such code is misunderstood.", CWE398, Certainty::normal);
}

static bool isLargeContainer(const Variable* var, const Settings* settings)
static bool isLargeContainer(const Variable* var, const Settings& settings)
{
const ValueType* vt = var->valueType();
if (vt->container->size_templateArgNo < 0)
return true;
const std::size_t maxByValueSize = 2 * settings->platform.sizeof_pointer;
const std::size_t maxByValueSize = 2 * settings.platform.sizeof_pointer;
if (var->dimensions().empty()) {
if (vt->container->startPattern == "std :: bitset <") {
if (const ValueFlow::Value* v = vt->containerTypeToken->getKnownValue(ValueFlow::Value::ValueType::INT))
return v->intvalue / 8 > maxByValueSize;
}
return false;
}
const ValueType vtElem = ValueType::parseDecl(vt->containerTypeToken, *settings);
const auto elemSize = std::max<std::size_t>(ValueFlow::getSizeOf(vtElem, *settings), 1);
const ValueType vtElem = ValueType::parseDecl(vt->containerTypeToken, settings);
const auto elemSize = std::max<std::size_t>(ValueFlow::getSizeOf(vtElem, settings), 1);
const auto arraySize = var->dimension(0) * elemSize;
return arraySize > maxByValueSize;
}
Expand Down Expand Up @@ -1438,7 +1438,7 @@ void CheckOther::checkPassByReference()
bool inconclusive = false;

const bool isContainer = var->valueType() && var->valueType()->type == ValueType::Type::CONTAINER && var->valueType()->container && !var->valueType()->container->view;
if (isContainer && !isLargeContainer(var, mSettings))
if (isContainer && !isLargeContainer(var, *mSettings))
continue;
if (!isContainer) {
if (var->type() && !var->type()->isEnumType()) { // Check if type is a struct or class.
Expand Down
2 changes: 1 addition & 1 deletion lib/forwardanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace {
traverseRecursive(tok->astOperand2(), f, traverseUnknown);
traverseRecursive(tok->astOperand1(), f, traverseUnknown);
return Break(Analyzer::Terminate::Escape);
} else if (Token::Match(tok, "%name% (") && isEscapeFunction(tok, &settings.library)) {
} else if (Token::Match(tok, "%name% (") && isEscapeFunction(tok, settings.library)) {
// Traverse the parameters of the function before escaping
traverseRecursive(tok->next()->astOperand2(), f, traverseUnknown);
return Break(Analyzer::Terminate::Escape);
Expand Down
4 changes: 2 additions & 2 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4647,7 +4647,7 @@ struct ConditionHandler {
if (!Token::Match(tok, "%assign%|++|--") &&
findExpression(cond.vartok->exprId(), start, end, [&](const Token* tok2) {
return Token::Match(tok2->astParent(), "%assign%") && astIsLHS(tok2);
}) && !findEscapeStatement(block->scope(), &settings.library)) {
}) && !findEscapeStatement(block->scope(), settings.library)) {
// Start at the end of the loop body
Token* bodyTok = top->link()->next();
reverse(bodyTok->link(), bodyTok, cond.vartok, values, tokenlist, errorLogger, settings);
Expand Down Expand Up @@ -5322,7 +5322,7 @@ static void valueFlowForLoopSimplify(Token* const bodyStart,
if (isVariableChanged(bodyStart, bodyEnd, expr->varId(), globalvar, settings))
return;

if (const Token* escape = findEscapeStatement(bodyStart->scope(), &settings.library)) {
if (const Token* escape = findEscapeStatement(bodyStart->scope(), settings.library)) {
if (settings.debugwarnings)
bailout(tokenlist, errorLogger, escape, "For loop variable bailout on escape statement");
return;
Expand Down
Loading