Skip to content

Commit 1858465

Browse files
committed
astyle formatting
[ci skip]
1 parent 5f21d9d commit 1858465

4 files changed

Lines changed: 73 additions & 77 deletions

File tree

lib/checkbufferoverrun.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -920,18 +920,18 @@ void CheckBufferOverrun::objectIndex()
920920
std::copy_if(idx->values().begin(),
921921
idx->values().end(),
922922
std::back_inserter(idxValues),
923-
[&](const ValueFlow::Value& vidx) {
924-
if (!vidx.isIntValue())
925-
return false;
926-
return vidx.path == v.path || vidx.path == 0;
927-
});
923+
[&](const ValueFlow::Value& vidx) {
924+
if (!vidx.isIntValue())
925+
return false;
926+
return vidx.path == v.path || vidx.path == 0;
927+
});
928928
if (idxValues.empty() ||
929-
std::any_of(idxValues.begin(), idxValues.end(), [&](const ValueFlow::Value& vidx) {
930-
if (vidx.isImpossible())
931-
return (vidx.intvalue == 0);
932-
else
933-
return (vidx.intvalue != 0);
934-
})) {
929+
std::any_of(idxValues.begin(), idxValues.end(), [&](const ValueFlow::Value& vidx) {
930+
if (vidx.isImpossible())
931+
return (vidx.intvalue == 0);
932+
else
933+
return (vidx.intvalue != 0);
934+
})) {
935935
objectIndexError(tok, &v, idx->hasKnownIntValue());
936936
}
937937
} else {

lib/checkstl.cpp

Lines changed: 51 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -854,30 +854,26 @@ struct InvalidContainerAnalyzer {
854854
};
855855
std::unordered_map<int, Reference> expressions;
856856
ErrorPath errorPath;
857-
void add(const std::vector<Reference>& refs)
858-
{
857+
void add(const std::vector<Reference>& refs) {
859858
for (const Reference& r : refs) {
860859
add(r);
861860
}
862861
}
863-
void add(const Reference& r)
864-
{
862+
void add(const Reference& r) {
865863
if (!r.tok)
866864
return;
867865
expressions.insert(std::make_pair(r.tok->exprId(), r));
868866
}
869867

870-
std::vector<Reference> invalidTokens() const
871-
{
868+
std::vector<Reference> invalidTokens() const {
872869
std::vector<Reference> result;
873870
std::transform(expressions.begin(), expressions.end(), std::back_inserter(result), SelectMapValues{});
874871
return result;
875872
}
876873
};
877874
std::unordered_map<const Function*, Info> invalidMethods;
878875

879-
std::vector<Info::Reference> invalidatesContainer(const Token* tok) const
880-
{
876+
std::vector<Info::Reference> invalidatesContainer(const Token* tok) const {
881877
std::vector<Info::Reference> result;
882878
if (Token::Match(tok, "%name% (")) {
883879
const Function* f = tok->function();
@@ -920,15 +916,14 @@ struct InvalidContainerAnalyzer {
920916
ErrorPath ep;
921917
ep.emplace_front(tok,
922918
"After calling '" + tok->strAt(2) +
923-
"', iterators or references to the container's data may be invalid .");
919+
"', iterators or references to the container's data may be invalid .");
924920
result.push_back(Info::Reference{tok, ep});
925921
}
926922
}
927923
return result;
928924
}
929925

930-
void analyze(const SymbolDatabase* symboldatabase)
931-
{
926+
void analyze(const SymbolDatabase* symboldatabase) {
932927
for (const Scope* scope : symboldatabase->functionScopes) {
933928
const Function* f = scope->function;
934929
if (!f)
@@ -990,55 +985,55 @@ void CheckStl::invalidContainer()
990985
const ValueFlow::Value* v = nullptr;
991986
ErrorPath errorPath;
992987
PathAnalysis::Info info =
993-
PathAnalysis{endToken, library}.forwardFind([&](const PathAnalysis::Info& info) {
994-
if (!info.tok->variable())
995-
return false;
996-
if (info.tok->varId() == 0)
997-
return false;
998-
if (skipVarIds.count(info.tok->varId()) > 0)
999-
return false;
1000-
// if (Token::simpleMatch(info.tok->next(), "."))
1001-
// return false;
1002-
if (Token::Match(info.tok->astParent(), "%assign%") && astIsLHS(info.tok))
1003-
skipVarIds.insert(info.tok->varId());
1004-
if (info.tok->variable()->isReference() && !isVariableDecl(info.tok) &&
1005-
reaches(info.tok->variable()->nameToken(), tok, library, nullptr)) {
1006-
1007-
ErrorPath ep;
1008-
bool addressOf = false;
1009-
const Variable* var = getLifetimeVariable(info.tok, ep, &addressOf);
1010-
// Check the reference is created before the change
1011-
if (var && var->declarationId() == r.tok->varId() && !addressOf) {
1012-
// An argument always reaches
1013-
if (var->isArgument() ||
1014-
(!var->isReference() && !var->isRValueReference() && !isVariableDecl(tok) &&
1015-
reaches(var->nameToken(), tok, library, &ep))) {
1016-
errorPath = ep;
1017-
return true;
1018-
}
1019-
}
1020-
}
1021-
for (const ValueFlow::Value& val : info.tok->values()) {
1022-
if (!val.isLocalLifetimeValue())
1023-
continue;
1024-
if (val.lifetimeKind == ValueFlow::Value::LifetimeKind::Address)
1025-
continue;
1026-
if (val.lifetimeKind == ValueFlow::Value::LifetimeKind::SubObject)
1027-
continue;
1028-
if (!val.tokvalue->variable())
1029-
continue;
1030-
if (val.tokvalue->varId() != r.tok->varId())
1031-
continue;
1032-
ErrorPath ep;
1033-
// Check the iterator is created before the change
1034-
if (val.tokvalue != tok && reaches(val.tokvalue, tok, library, &ep)) {
1035-
v = &val;
988+
PathAnalysis{endToken, library} .forwardFind([&](const PathAnalysis::Info& info) {
989+
if (!info.tok->variable())
990+
return false;
991+
if (info.tok->varId() == 0)
992+
return false;
993+
if (skipVarIds.count(info.tok->varId()) > 0)
994+
return false;
995+
// if (Token::simpleMatch(info.tok->next(), "."))
996+
// return false;
997+
if (Token::Match(info.tok->astParent(), "%assign%") && astIsLHS(info.tok))
998+
skipVarIds.insert(info.tok->varId());
999+
if (info.tok->variable()->isReference() && !isVariableDecl(info.tok) &&
1000+
reaches(info.tok->variable()->nameToken(), tok, library, nullptr)) {
1001+
1002+
ErrorPath ep;
1003+
bool addressOf = false;
1004+
const Variable* var = getLifetimeVariable(info.tok, ep, &addressOf);
1005+
// Check the reference is created before the change
1006+
if (var && var->declarationId() == r.tok->varId() && !addressOf) {
1007+
// An argument always reaches
1008+
if (var->isArgument() ||
1009+
(!var->isReference() && !var->isRValueReference() && !isVariableDecl(tok) &&
1010+
reaches(var->nameToken(), tok, library, &ep))) {
10361011
errorPath = ep;
10371012
return true;
10381013
}
10391014
}
1040-
return false;
1041-
});
1015+
}
1016+
for (const ValueFlow::Value& val : info.tok->values()) {
1017+
if (!val.isLocalLifetimeValue())
1018+
continue;
1019+
if (val.lifetimeKind == ValueFlow::Value::LifetimeKind::Address)
1020+
continue;
1021+
if (val.lifetimeKind == ValueFlow::Value::LifetimeKind::SubObject)
1022+
continue;
1023+
if (!val.tokvalue->variable())
1024+
continue;
1025+
if (val.tokvalue->varId() != r.tok->varId())
1026+
continue;
1027+
ErrorPath ep;
1028+
// Check the iterator is created before the change
1029+
if (val.tokvalue != tok && reaches(val.tokvalue, tok, library, &ep)) {
1030+
v = &val;
1031+
errorPath = ep;
1032+
return true;
1033+
}
1034+
}
1035+
return false;
1036+
});
10421037
if (!info.tok)
10431038
continue;
10441039
errorPath.insert(errorPath.end(), info.errorPath.begin(), info.errorPath.end());

lib/utils.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@
3030

3131
struct SelectMapKeys {
3232
template <class Pair>
33-
typename Pair::first_type operator()(const Pair& p) const
34-
{
33+
typename Pair::first_type operator()(const Pair& p) const {
3534
return p.first;
3635
}
3736
};
3837

3938
struct SelectMapValues {
4039
template <class Pair>
41-
typename Pair::second_type operator()(const Pair& p) const
42-
{
40+
typename Pair::second_type operator()(const Pair& p) const {
4341
return p.second;
4442
}
4543
};

lib/valueflow.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,21 @@ static bool isComputableValue(const Token* parent, const ValueFlow::Value& value
353353
}
354354

355355
template<class T>
356-
static bool isEqual(T x, T y) {
356+
static bool isEqual(T x, T y)
357+
{
357358
return x == y;
358359
}
359360

360361
template<>
361-
bool isEqual<double>(double x, double y) {
362+
bool isEqual<double>(double x, double y)
363+
{
362364
const double diff = (x > y) ? x - y : y - x;
363365
return !((diff / 2) < diff);
364366
}
365367

366368
template<class T>
367-
static bool isZero(T x) {
369+
static bool isZero(T x)
370+
{
368371
return isEqual<T>(x, T(0));
369372
}
370373

@@ -2306,8 +2309,8 @@ struct OppositeExpressionAnalyzer : ExpressionAnalyzer {
23062309
OppositeExpressionAnalyzer() : ExpressionAnalyzer(), isNot(false) {}
23072310

23082311
OppositeExpressionAnalyzer(bool pIsNot, const Token* e, const ValueFlow::Value& val, const TokenList* t)
2309-
: ExpressionAnalyzer(e, val, t), isNot(pIsNot)
2310-
{}
2312+
: ExpressionAnalyzer(e, val, t), isNot(pIsNot)
2313+
{}
23112314

23122315
virtual bool match(const Token* tok) const OVERRIDE {
23132316
return isOppositeCond(isNot, isCPP(), expr, tok, getSettings()->library, true, true);
@@ -4973,7 +4976,7 @@ struct MultiValueFlowAnalyzer : ValueFlowAnalyzer {
49734976
if (scope && condTok)
49744977
programMemoryParseCondition(pm, condTok, nullptr, getSettings(), scope->type != Scope::eElse);
49754978
// ProgramMemory pm = pms.get(endBlock->link()->next(), getProgramState());
4976-
for(const auto& p:pm.values) {
4979+
for (const auto& p:pm.values) {
49774980
int varid = p.first;
49784981
ValueFlow::Value value = p.second;
49794982
if (vars.count(varid) != 0)

0 commit comments

Comments
 (0)