Skip to content

Commit 35672d3

Browse files
committed
added bailout message TODOs [skip ci]
1 parent 36f886a commit 35672d3

7 files changed

Lines changed: 55 additions & 17 deletions

File tree

lib/astutils.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ const Token* findExpression(const nonneg int exprid,
6969
static int findArgumentPosRecursive(const Token* tok, const Token* tokToFind, bool &found, nonneg int depth=0)
7070
{
7171
++depth;
72-
if (!tok || depth >= 100)
72+
if (!tok || depth >= 100) {
73+
// TODO: add bailout message
7374
return -1;
75+
}
7476
if (tok->str() == ",") {
7577
int res = findArgumentPosRecursive(tok->astOperand1(), tokToFind, found, depth);
7678
if (res == -1)
@@ -112,8 +114,10 @@ template<class T, class OuputIterator, REQUIRES("T must be a Token class", std::
112114
static void astFlattenCopy(T* tok, const char* op, OuputIterator out, nonneg int depth = 100)
113115
{
114116
--depth;
115-
if (!tok || depth < 0)
117+
if (!tok || depth < 0) {
118+
// TODO: add bailout message
116119
return;
120+
}
117121
if (strcmp(tok->str().c_str(), op) == 0) {
118122
astFlattenCopy(tok->astOperand1(), op, out, depth);
119123
astFlattenCopy(tok->astOperand2(), op, out, depth);
@@ -140,8 +144,10 @@ std::vector<Token*> astFlatten(Token* tok, const char* op)
140144
nonneg int astCount(const Token* tok, const char* op, int depth)
141145
{
142146
--depth;
143-
if (!tok || depth < 0)
147+
if (!tok || depth < 0) {
148+
// TODO: add bailout message
144149
return 0;
150+
}
145151
if (strcmp(tok->str().c_str(), op) == 0)
146152
return astCount(tok->astOperand1(), op, depth) + astCount(tok->astOperand2(), op, depth);
147153
return 1;
@@ -1119,6 +1125,7 @@ bool exprDependsOnThis(const Token* expr, bool onVar, nonneg int depth)
11191125
return true;
11201126
if (depth >= 1000)
11211127
// Abort recursion to avoid stack overflow
1128+
// TODO: add bailout message
11221129
return true;
11231130
++depth;
11241131

@@ -1256,6 +1263,7 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
12561263
if (!tok)
12571264
return {};
12581265
if (depth < 0) {
1266+
// TODO: add bailout message
12591267
SmallVector<ReferenceToken> refs_result;
12601268
refs_result.emplace_back(tok, std::move(errors));
12611269
return refs_result;
@@ -2855,8 +2863,10 @@ static bool isExpressionChangedAt(const F& getExprTok,
28552863
const Settings& settings,
28562864
int depth)
28572865
{
2858-
if (depth < 0)
2866+
if (depth < 0) {
2867+
// TODO: add bailout message
28592868
return true;
2869+
}
28602870
if (!isMutableExpression(tok))
28612871
return false;
28622872
if (tok->exprId() != exprid || (!tok->varId() && !tok->isName())) {
@@ -2906,8 +2916,10 @@ Token* findVariableChanged(Token *start, const Token *end, int indirect, const n
29062916
{
29072917
if (!precedes(start, end))
29082918
return nullptr;
2909-
if (depth < 0)
2919+
if (depth < 0) {
2920+
// TODO: add bailout message
29102921
return start;
2922+
}
29112923
auto getExprTok = memoize([&] {
29122924
return findExpression(start, exprid);
29132925
});
@@ -3005,8 +3017,10 @@ static const Token* findExpressionChangedImpl(const Token* expr,
30053017
int depth,
30063018
Find find)
30073019
{
3008-
if (depth < 0)
3020+
if (depth < 0) {
3021+
// TODO: add bailout message
30093022
return start;
3023+
}
30103024
if (!precedes(start, end))
30113025
return nullptr;
30123026
const Token* result = nullptr;

lib/checkstl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,10 @@ static const ValueFlow::Value* getInnerLifetime(const Token* tok,
10581058
ErrorPath* errorPath = nullptr,
10591059
int depth = 4)
10601060
{
1061-
if (depth < 0)
1061+
if (depth < 0) {
1062+
// TODO: add bailout message
10621063
return nullptr;
1064+
}
10631065
if (!tok)
10641066
return nullptr;
10651067
for (const ValueFlow::Value& val : tok->values()) {

lib/forwardanalyzer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,10 @@ namespace {
550550
}
551551

552552
Progress updateRange(Token* start, const Token* end, int depth = 20) {
553-
if (depth < 0)
553+
if (depth < 0) {
554+
// TODO: add bailout message
554555
return Break(Analyzer::Terminate::Bail);
556+
}
555557
std::size_t i = 0;
556558
for (Token* tok = start; precedes(tok, end); tok = tok->next()) {
557559
Token* next = nullptr;

lib/programmemory.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,8 +1346,10 @@ namespace {
13461346
}
13471347

13481348
nonneg int n = astCount(expr, expr->str().c_str());
1349-
if (n > 50)
1349+
if (n > 50) {
1350+
// TODO: add bailout message
13501351
return unknown();
1352+
}
13511353
std::vector<const Token*> conditions1 = flattenConditions(expr);
13521354
if (conditions1.empty())
13531355
return unknown();
@@ -1364,8 +1366,10 @@ namespace {
13641366
}
13651367
if (condValues.size() == conditions1.size() && allNegated)
13661368
return negatedValue;
1367-
if (n > 4)
1369+
if (n > 4) {
1370+
// TODO: add bailout message
13681371
return unknown();
1372+
}
13691373
if (!sortConditions(conditions1))
13701374
return unknown();
13711375

@@ -1599,6 +1603,7 @@ namespace {
15991603
return execute(tok);
16001604
});
16011605
if (f) {
1606+
// TODO: add bailout message
16021607
if (fdepth >= 0 && !f->isImplicitlyVirtual()) {
16031608
ProgramMemory functionState;
16041609
for (std::size_t i = 0; i < args.size(); ++i) {
@@ -1687,8 +1692,10 @@ namespace {
16871692
OnExit onExit{[&] {
16881693
depth++;
16891694
}};
1690-
if (depth < 0)
1695+
if (depth < 0) {
1696+
// TODO: add bailout message
16911697
return unknown();
1698+
}
16921699
ValueFlow::Value v = unknown();
16931700
if (updateValue(v, executeImpl(expr)))
16941701
return v;

lib/valueflow.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,10 @@ static std::vector<ValueFlow::LifetimeToken> getLifetimeTokens(const Token* tok,
729729
const Variable *var = tok->variable();
730730
if (pred(tok))
731731
return {{tok, std::move(errorPath)}};
732-
if (depth < 0)
732+
if (depth < 0) {
733+
// TODO: add bailout message
733734
return {{tok, std::move(errorPath)}};
735+
}
734736
if (var && var->declarationId() == tok->varId()) {
735737
if (var->isReference() || var->isRValueReference()) {
736738
const Token * const varDeclEndToken = var->declEndToken();
@@ -1516,8 +1518,10 @@ struct LifetimeStore {
15161518

15171519
static bool hasBorrowingVariables(const std::list<Variable>& vars, const std::vector<const Token*>& args, int depth = 10)
15181520
{
1519-
if (depth < 0)
1521+
if (depth < 0) {
1522+
// TODO: add bailout message
15201523
return true;
1524+
}
15211525
return std::any_of(vars.cbegin(), vars.cend(), [&](const Variable& var) {
15221526
if (const ValueType* vt = var.valueType()) {
15231527
if (vt->pointer > 0 &&
@@ -2578,8 +2582,10 @@ static void valueFlowSymbolic(const TokenList& tokenlist, const SymbolDatabase&
25782582

25792583
static const Token* isStrlenOf(const Token* tok, const Token* expr, int depth = 10)
25802584
{
2581-
if (depth < 0)
2585+
if (depth < 0) {
2586+
// TODO: add bailout message
25822587
return nullptr;
2588+
}
25832589
if (!tok)
25842590
return nullptr;
25852591
if (!expr)
@@ -4752,6 +4758,7 @@ static bool isContainerSizeChangedByFunction(const Token* tok,
47524758
// Argument not used
47534759
if (!arg->nameToken())
47544760
return false;
4761+
// TODO: add bailout message
47554762
if (depth > 0)
47564763
return isContainerSizeChanged(arg->nameToken(),
47574764
scope->bodyStart,

lib/vf_analyzers.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ struct ValueFlowAnalyzer : Analyzer {
107107
ConditionState result;
108108
if (!tok)
109109
return result;
110-
if (depth < 0)
110+
if (depth < 0) {
111+
// TODO: add bailout message
111112
return result;
113+
}
112114
depth--;
113115
if (analyze(tok, Direction::Forward).isRead()) {
114116
result.dependent = true;
@@ -804,8 +806,10 @@ static bool bifurcateVariableChanged(const Variable* var,
804806

805807
static bool bifurcate(const Token* tok, const std::set<nonneg int>& varids, const Settings& settings, int depth)
806808
{
807-
if (depth < 0)
809+
if (depth < 0) {
810+
// TODO: add bailout message
808811
return false;
812+
}
809813
if (!tok)
810814
return true;
811815
if (tok->hasKnownIntValue())

lib/vf_impossiblevalues.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ namespace ValueFlow
4545
std::vector<MathLib::bigint> result;
4646
if (!tok)
4747
return result;
48-
if (depth < 0)
48+
if (depth < 0) {
49+
// TODO: add bailout message
4950
return result;
51+
}
5052
if (tok->hasKnownIntValue()) {
5153
result = {tok->values().front().intvalue};
5254
} else if (!Token::Match(tok, "-|%|&|^") && tok->isConstOp() && tok->astOperand1() && tok->astOperand2()) {

0 commit comments

Comments
 (0)