Skip to content

Commit ce90855

Browse files
committed
fixed some -Wnrvo Clang compiler warnings
1 parent d69955c commit ce90855

File tree

12 files changed

+140
-116
lines changed

12 files changed

+140
-116
lines changed

lib/checkbufferoverrun.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ static std::vector<ValueFlow::Value> getOverrunIndexValues(const Token* tok,
284284
overflow = true;
285285
indexValues.push_back(values.front());
286286
}
287-
if (overflow)
288-
return indexValues;
289-
return {};
287+
if (!overflow)
288+
indexValues.clear();
289+
return indexValues;
290290
}
291291

292292
void CheckBufferOverrun::arrayIndex()

lib/checkstl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static std::string indexValueString(const ValueFlow::Value& indexValue, const st
216216
indexString += "+" + MathLib::toString(indexValue.intvalue);
217217
}
218218
if (indexValue.bound == ValueFlow::Value::Bound::Lower)
219-
return "greater or equal to " + indexString;
219+
indexString = "greater or equal to " + indexString;
220220
return indexString;
221221
}
222222

lib/errorlogger.cpp

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,47 +1055,49 @@ std::string getGuideline(const std::string &errId, ReportType reportType,
10551055
const std::map<std::string, std::string> &guidelineMapping,
10561056
Severity severity)
10571057
{
1058-
std::string guideline;
1058+
{
1059+
std::string guideline;
10591060

1060-
switch (reportType) {
1061-
case ReportType::autosar:
1062-
if (errId.rfind("premium-autosar-", 0) == 0) {
1063-
guideline = errId.substr(16);
1061+
switch (reportType) {
1062+
case ReportType::autosar:
1063+
if (errId.rfind("premium-autosar-", 0) == 0) {
1064+
guideline = errId.substr(16);
1065+
break;
1066+
}
1067+
if (errId.rfind("premium-misra-cpp-2008-", 0) == 0)
1068+
guideline = "M" + errId.substr(23);
1069+
break;
1070+
case ReportType::certC:
1071+
case ReportType::certCpp:
1072+
if (errId.rfind("premium-cert-", 0) == 0) {
1073+
guideline = errId.substr(13);
1074+
std::transform(guideline.begin(), guideline.end(),
1075+
guideline.begin(), static_cast<int (*)(int)>(std::toupper));
1076+
}
1077+
break;
1078+
case ReportType::misraC2012:
1079+
case ReportType::misraC2023:
1080+
case ReportType::misraC2025:
1081+
if (errId.rfind("misra-c20", 0) == 0 || errId.rfind("premium-misra-c-20", 0) == 0)
1082+
guideline = errId.substr(errId.rfind('-') + 1);
1083+
break;
1084+
case ReportType::misraCpp2008:
1085+
if (errId.rfind("premium-misra-cpp-2008", 0) == 0)
1086+
guideline = errId.substr(23);
1087+
break;
1088+
case ReportType::misraCpp2023:
1089+
if (errId.rfind("premium-misra-cpp-2023", 0) == 0)
1090+
guideline = errId.substr(errId.rfind('-') + 1);
1091+
break;
1092+
default:
10641093
break;
10651094
}
1066-
if (errId.rfind("premium-misra-cpp-2008-", 0) == 0)
1067-
guideline = "M" + errId.substr(23);
1068-
break;
1069-
case ReportType::certC:
1070-
case ReportType::certCpp:
1071-
if (errId.rfind("premium-cert-", 0) == 0) {
1072-
guideline = errId.substr(13);
1073-
std::transform(guideline.begin(), guideline.end(),
1074-
guideline.begin(), static_cast<int (*)(int)>(std::toupper));
1075-
}
1076-
break;
1077-
case ReportType::misraC2012:
1078-
case ReportType::misraC2023:
1079-
case ReportType::misraC2025:
1080-
if (errId.rfind("misra-c20", 0) == 0 || errId.rfind("premium-misra-c-20", 0) == 0)
1081-
guideline = errId.substr(errId.rfind('-') + 1);
1082-
break;
1083-
case ReportType::misraCpp2008:
1084-
if (errId.rfind("premium-misra-cpp-2008", 0) == 0)
1085-
guideline = errId.substr(23);
1086-
break;
1087-
case ReportType::misraCpp2023:
1088-
if (errId.rfind("premium-misra-cpp-2023", 0) == 0)
1089-
guideline = errId.substr(errId.rfind('-') + 1);
1090-
break;
1091-
default:
1092-
break;
1093-
}
10941095

1095-
if (!guideline.empty()) {
1096-
if (errId.find("-dir-") != std::string::npos)
1097-
guideline = "Dir " + guideline;
1098-
return guideline;
1096+
if (!guideline.empty()) {
1097+
if (errId.find("-dir-") != std::string::npos)
1098+
guideline = "Dir " + guideline;
1099+
return guideline;
1100+
}
10991101
}
11001102

11011103
auto it = guidelineMapping.find(errId);

lib/fwdanalysis.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
139139
if (!opTok)
140140
opTok = tok->next();
141141
std::pair<const Token*, const Token*> startEndTokens = opTok->findExpressionStartEndTokens();
142-
FwdAnalysis::Result result =
143-
checkRecursive(expr, startEndTokens.first, startEndTokens.second->next(), exprVarIds, local, true, depth);
144-
if (result.type != Result::Type::NONE)
145-
return result;
142+
{
143+
FwdAnalysis::Result result =
144+
checkRecursive(expr, startEndTokens.first, startEndTokens.second->next(), exprVarIds, local, true, depth);
145+
if (result.type != Result::Type::NONE)
146+
return result;
147+
}
146148

147149
// #9167: if the return is inside an inner class, it does not tell us anything
148150
if (!inInnerClass) {

lib/library.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,8 @@ std::string Library::getFunctionName(const Token *ftok) const
12131213
const Token * tok = ftok->astParent()->isUnaryOp("&") ? ftok->astParent()->astOperand1() : ftok->next()->astOperand1();
12141214
std::string ret = getFunctionName(tok, error);
12151215
if (error)
1216-
return {};
1217-
if (startsWith(ret, "::"))
1216+
ret.clear();
1217+
else if (startsWith(ret, "::"))
12181218
ret.erase(0, 2);
12191219
return ret;
12201220
}

lib/mathlib.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,9 @@ template<> std::string MathLib::toString<double>(double value)
564564
result << value;
565565
std::string s = result.str();
566566
if (s == "-0")
567-
return "0.0";
568-
if (s.find_first_of(".e") == std::string::npos)
569-
return s + ".0";
567+
s = "0.0";
568+
else if (s.find_first_of(".e") == std::string::npos)
569+
s += ".0";
570570
return s;
571571
}
572572

lib/programmemory.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,17 +1395,19 @@ namespace {
13951395
return unknown();
13961396
std::unordered_map<nonneg int, ValueFlow::Value> condValues = executeAll(conditions1, &b);
13971397
bool allNegated = true;
1398-
ValueFlow::Value negatedValue = unknown();
1399-
for (const auto& p : condValues) {
1400-
const ValueFlow::Value& v = p.second;
1401-
if (isTrueOrFalse(v, b))
1402-
return v;
1403-
allNegated &= isTrueOrFalse(v, !b);
1404-
if (allNegated && negatedValue.isUninitValue())
1405-
negatedValue = v;
1398+
{
1399+
ValueFlow::Value negatedValue = unknown();
1400+
for (const auto& p : condValues) {
1401+
const ValueFlow::Value& v = p.second;
1402+
if (isTrueOrFalse(v, b))
1403+
return v;
1404+
allNegated &= isTrueOrFalse(v, !b);
1405+
if (allNegated && negatedValue.isUninitValue())
1406+
negatedValue = v;
1407+
}
1408+
if (condValues.size() == conditions1.size() && allNegated)
1409+
return negatedValue;
14061410
}
1407-
if (condValues.size() == conditions1.size() && allNegated)
1408-
return negatedValue;
14091411
if (n > 4)
14101412
return unknown();
14111413
if (!sortConditions(conditions1))
@@ -1805,7 +1807,7 @@ namespace {
18051807
if (elseStart)
18061808
result = execute(elseStart->scope());
18071809
} else {
1808-
return {unknown()};
1810+
result = {unknown()};
18091811
}
18101812
if (!result.empty())
18111813
return result;

lib/symboldatabase.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8131,10 +8131,13 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings &sett
81318131

81328132
std::string ValueType::dump() const
81338133
{
8134+
if (type == UNKNOWN_TYPE)
8135+
return "";
8136+
81348137
std::string ret;
81358138
switch (type) {
81368139
case UNKNOWN_TYPE:
8137-
return "";
8140+
break; // never happens
81388141
case NONSTD:
81398142
ret += "valueType-type=\"nonstd\"";
81408143
break;

lib/token.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,9 +2438,11 @@ std::pair<const Token*, const Token*> Token::typeDecl(const Token* tok, bool poi
24382438
varTok = varTok->next();
24392439
while (Token::Match(varTok, "%name% ::"))
24402440
varTok = varTok->tokAt(2);
2441-
std::pair<const Token*, const Token*> r = typeDecl(varTok);
2442-
if (r.first)
2443-
return r;
2441+
{
2442+
std::pair<const Token*, const Token*> r = typeDecl(varTok);
2443+
if (r.first)
2444+
return r;
2445+
}
24442446

24452447
if (pointedToType && tok2->astOperand1() && Token::simpleMatch(tok2, "new")) {
24462448
if (Token::simpleMatch(tok2->astOperand1(), "("))

lib/valueflow.cpp

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,11 @@ static void valueFlowTypeTraits(TokenList& tokenlist, const Settings& settings)
781781
eval["is_reference"] = [&](const std::vector<std::vector<const Token*>>& args) {
782782
if (args.size() != 1)
783783
return ValueFlow::Value::unknown();
784-
ValueFlow::Value isRValue = eval["is_rvalue_reference"](args);
785-
if (isRValue.isUninitValue() || isRValue.intvalue == 1)
786-
return isRValue;
784+
{
785+
ValueFlow::Value isRValue = eval["is_rvalue_reference"](args);
786+
if (isRValue.isUninitValue() || isRValue.intvalue == 1)
787+
return isRValue;
788+
}
787789
return eval["is_lvalue_reference"](args);
788790
};
789791
for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
@@ -5116,21 +5118,22 @@ static void valueFlowCondition(const ValuePtr<ConditionHandler>& handler,
51165118

51175119
struct SimpleConditionHandler : ConditionHandler {
51185120
std::vector<Condition> parse(const Token* tok, const Settings& /*settings*/) const override {
5119-
5120-
std::vector<Condition> conds;
5121-
parseCompareEachInt(tok, [&](const Token* vartok, ValueFlow::Value true_value, ValueFlow::Value false_value) {
5122-
if (vartok->hasKnownIntValue())
5123-
return;
5124-
if (vartok->str() == "=" && vartok->astOperand1() && vartok->astOperand2())
5125-
vartok = vartok->astOperand1();
5126-
Condition cond;
5127-
cond.true_values.push_back(std::move(true_value));
5128-
cond.false_values.push_back(std::move(false_value));
5129-
cond.vartok = vartok;
5130-
conds.push_back(std::move(cond));
5131-
});
5132-
if (!conds.empty())
5133-
return conds;
5121+
{
5122+
std::vector<Condition> conds;
5123+
parseCompareEachInt(tok, [&](const Token* vartok, ValueFlow::Value true_value, ValueFlow::Value false_value) {
5124+
if (vartok->hasKnownIntValue())
5125+
return;
5126+
if (vartok->str() == "=" && vartok->astOperand1() && vartok->astOperand2())
5127+
vartok = vartok->astOperand1();
5128+
Condition cond;
5129+
cond.true_values.push_back(std::move(true_value));
5130+
cond.false_values.push_back(std::move(false_value));
5131+
cond.vartok = vartok;
5132+
conds.push_back(std::move(cond));
5133+
});
5134+
if (!conds.empty())
5135+
return conds;
5136+
}
51345137

51355138
const Token* vartok = nullptr;
51365139

@@ -6637,9 +6640,11 @@ static std::vector<ValueFlow::Value> getContainerSizeFromConstructorArgs(const s
66376640
} else if (astIsContainer(args[0]) && args.size() == 1) { // copy constructor
66386641
return getContainerValues(args[0]);
66396642
} else if (isIteratorPair(args)) {
6640-
std::vector<ValueFlow::Value> result = getContainerValues(args[0]);
6641-
if (!result.empty())
6642-
return result;
6643+
{
6644+
std::vector<ValueFlow::Value> result = getContainerValues(args[0]);
6645+
if (!result.empty())
6646+
return result;
6647+
}
66436648
// (ptr, ptr + size)
66446649
if (astIsPointer(args[0]) && args[0]->exprId() != 0) {
66456650
// (ptr, ptr) is empty
@@ -6940,21 +6945,23 @@ static void valueFlowContainerSize(const TokenList& tokenlist,
69406945
struct ContainerConditionHandler : ConditionHandler {
69416946
std::vector<Condition> parse(const Token* tok, const Settings& settings) const override
69426947
{
6943-
std::vector<Condition> conds;
6944-
parseCompareEachInt(tok, [&](const Token* vartok, ValueFlow::Value true_value, ValueFlow::Value false_value) {
6945-
vartok = settings.library.getContainerFromYield(vartok, Library::Container::Yield::SIZE);
6946-
if (!vartok)
6947-
return;
6948-
true_value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
6949-
false_value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
6950-
Condition cond;
6951-
cond.true_values.push_back(std::move(true_value));
6952-
cond.false_values.push_back(std::move(false_value));
6953-
cond.vartok = vartok;
6954-
conds.push_back(std::move(cond));
6955-
});
6956-
if (!conds.empty())
6957-
return conds;
6948+
{
6949+
std::vector<Condition> conds;
6950+
parseCompareEachInt(tok, [&](const Token* vartok, ValueFlow::Value true_value, ValueFlow::Value false_value) {
6951+
vartok = settings.library.getContainerFromYield(vartok, Library::Container::Yield::SIZE);
6952+
if (!vartok)
6953+
return;
6954+
true_value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
6955+
false_value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
6956+
Condition cond;
6957+
cond.true_values.push_back(std::move(true_value));
6958+
cond.false_values.push_back(std::move(false_value));
6959+
cond.vartok = vartok;
6960+
conds.push_back(std::move(cond));
6961+
});
6962+
if (!conds.empty())
6963+
return conds;
6964+
}
69586965

69596966
const Token* vartok = nullptr;
69606967

@@ -7645,10 +7652,12 @@ std::vector<ValueFlow::Value> ValueFlow::isOutOfBounds(const Value& size, const
76457652
ValueFlow::Value inBoundsValue = inferCondition("<", indexTok, size.intvalue);
76467653
if (inBoundsValue.isKnown() && inBoundsValue.intvalue != 0)
76477654
return {};
7648-
std::vector<ValueFlow::Value> result = isOutOfBoundsImpl(size, indexTok, false);
7649-
if (!result.empty())
7650-
return result;
7655+
{
7656+
std::vector<ValueFlow::Value> result = isOutOfBoundsImpl(size, indexTok, false);
7657+
if (!result.empty())
7658+
return result;
7659+
}
76517660
if (!possible)
7652-
return result;
7661+
return {};
76537662
return isOutOfBoundsImpl(size, indexTok, true);
76547663
}

0 commit comments

Comments
 (0)