Write the clang-tidy file OpenBMC needs
Now that CI can handle clang-tidy, and a lot of the individual fixes
have landed for the various static analysis checks, lets see how close
we are.
This includes bringing a bunch of the code up to par with the checks
that require. Most of them fall into the category of extraneous else
statements, const correctness problems, or extra copies.
Tested:
CI only. Unit tests pass.
Signed-off-by: Ed Tanous <ed@tanous.net>
Change-Id: I9fbd346560a75fdd3901fa40c57932486275e912
diff --git a/.clang-tidy b/.clang-tidy
index 33b0960..67c3f8a 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -1,5 +1,244 @@
-Checks: '-*,readability-identifier-naming'
-WarningsAsErrors: '-*,readability-identifier-naming'
+Checks: '
+-*,
+readability-identifier-naming,
+clang-analyzer-apiModeling.StdCLibraryFunctions,
+clang-analyzer-apiModeling.TrustNonnull,
+clang-analyzer-apiModeling.google.GTest,
+clang-analyzer-apiModeling.llvm.CastValue,
+clang-analyzer-apiModeling.llvm.ReturnValue,
+clang-analyzer-core.CallAndMessage,
+clang-analyzer-core.CallAndMessageModeling,
+clang-analyzer-core.DivideZero,
+clang-analyzer-core.DynamicTypePropagation,
+clang-analyzer-core.NonNullParamChecker,
+clang-analyzer-core.NonnilStringConstants,
+clang-analyzer-core.NullDereference,
+clang-analyzer-core.StackAddrEscapeBase,
+clang-analyzer-core.StackAddressEscape,
+clang-analyzer-core.UndefinedBinaryOperatorResult,
+clang-analyzer-core.VLASize,
+clang-analyzer-core.builtin.BuiltinFunctions,
+clang-analyzer-core.builtin.NoReturnFunctions,
+clang-analyzer-core.uninitialized.ArraySubscript,
+clang-analyzer-core.uninitialized.Assign,
+clang-analyzer-core.uninitialized.Branch,
+clang-analyzer-core.uninitialized.CapturedBlockVariable,
+clang-analyzer-core.uninitialized.UndefReturn,
+clang-analyzer-cplusplus.InnerPointer,
+clang-analyzer-cplusplus.Move,
+clang-analyzer-cplusplus.NewDelete,
+clang-analyzer-cplusplus.NewDeleteLeaks,
+clang-analyzer-cplusplus.PlacementNew,
+clang-analyzer-cplusplus.PureVirtualCall,
+clang-analyzer-cplusplus.SelfAssignment,
+clang-analyzer-cplusplus.SmartPtrModeling,
+clang-analyzer-cplusplus.VirtualCallModeling,
+clang-analyzer-deadcode.DeadStores,
+clang-analyzer-fuchsia.HandleChecker,
+clang-analyzer-nullability.NullPassedToNonnull,
+clang-analyzer-nullability.NullReturnedFromNonnull,
+clang-analyzer-nullability.NullabilityBase,
+clang-analyzer-nullability.NullableDereferenced,
+clang-analyzer-nullability.NullablePassedToNonnull,
+clang-analyzer-nullability.NullableReturnedFromNonnull,
+clang-analyzer-optin.cplusplus.UninitializedObject,
+clang-analyzer-optin.cplusplus.VirtualCall,
+clang-analyzer-optin.mpi.MPI-Checker,
+clang-analyzer-optin.osx.OSObjectCStyleCast,
+clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,
+clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker,
+clang-analyzer-optin.performance.GCDAntipattern,
+clang-analyzer-optin.performance.Padding,
+clang-analyzer-optin.portability.UnixAPI,
+clang-analyzer-osx.API,
+clang-analyzer-osx.MIG,
+clang-analyzer-osx.NSOrCFErrorDerefChecker,
+clang-analyzer-osx.NumberObjectConversion,
+clang-analyzer-osx.OSObjectRetainCount,
+clang-analyzer-osx.ObjCProperty,
+clang-analyzer-osx.SecKeychainAPI,
+clang-analyzer-osx.cocoa.AtSync,
+clang-analyzer-osx.cocoa.AutoreleaseWrite,
+clang-analyzer-osx.cocoa.ClassRelease,
+clang-analyzer-osx.cocoa.Dealloc,
+clang-analyzer-osx.cocoa.IncompatibleMethodTypes,
+clang-analyzer-osx.cocoa.Loops,
+clang-analyzer-osx.cocoa.MissingSuperCall,
+clang-analyzer-osx.cocoa.NSAutoreleasePool,
+clang-analyzer-osx.cocoa.NSError,
+clang-analyzer-osx.cocoa.NilArg,
+clang-analyzer-osx.cocoa.NonNilReturnValue,
+clang-analyzer-osx.cocoa.ObjCGenerics,
+clang-analyzer-osx.cocoa.RetainCount,
+clang-analyzer-osx.cocoa.RetainCountBase,
+clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak,
+clang-analyzer-osx.cocoa.SelfInit,
+clang-analyzer-osx.cocoa.SuperDealloc,
+clang-analyzer-osx.cocoa.UnusedIvars,
+clang-analyzer-osx.cocoa.VariadicMethodTypes,
+clang-analyzer-osx.coreFoundation.CFError,
+clang-analyzer-osx.coreFoundation.CFNumber,
+clang-analyzer-osx.coreFoundation.CFRetainRelease,
+clang-analyzer-osx.coreFoundation.containers.OutOfBounds,
+clang-analyzer-osx.coreFoundation.containers.PointerSizedValues,
+clang-analyzer-security.FloatLoopCounter,
+clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
+clang-analyzer-security.insecureAPI.SecuritySyntaxChecker,
+clang-analyzer-security.insecureAPI.UncheckedReturn,
+clang-analyzer-security.insecureAPI.bcmp,
+clang-analyzer-security.insecureAPI.bcopy,
+clang-analyzer-security.insecureAPI.bzero,
+clang-analyzer-security.insecureAPI.decodeValueOfObjCType,
+clang-analyzer-security.insecureAPI.getpw,
+clang-analyzer-security.insecureAPI.gets,
+clang-analyzer-security.insecureAPI.mkstemp,
+clang-analyzer-security.insecureAPI.mktemp,
+clang-analyzer-security.insecureAPI.rand,
+clang-analyzer-security.insecureAPI.strcpy,
+clang-analyzer-security.insecureAPI.vfork,
+clang-analyzer-unix.API,
+clang-analyzer-unix.DynamicMemoryModeling,
+clang-analyzer-unix.Malloc,
+clang-analyzer-unix.MallocSizeof,
+clang-analyzer-unix.MismatchedDeallocator,
+clang-analyzer-unix.Vfork,
+clang-analyzer-unix.cstring.BadSizeArg,
+clang-analyzer-unix.cstring.CStringModeling,
+clang-analyzer-unix.cstring.NullArg,
+clang-analyzer-valist.CopyToSelf,
+clang-analyzer-valist.Uninitialized,
+clang-analyzer-valist.Unterminated,
+clang-analyzer-valist.ValistBase,
+clang-analyzer-webkit.NoUncountedMemberChecker,
+clang-analyzer-webkit.RefCntblBaseVirtualDtor,
+cert-con36-c,
+cert-con54-cpp,
+cert-dcl03-c,
+cert-dcl16-c,
+cert-dcl21-cpp,
+cert-dcl37-c,
+cert-dcl50-cpp,
+cert-dcl51-cpp,
+cert-dcl54-cpp,
+cert-dcl58-cpp,
+cert-dcl59-cpp,
+cert-env33-c,
+cert-err09-cpp,
+cert-err34-c,
+cert-err52-cpp,
+cert-err60-cpp,
+cert-err61-cpp,
+cert-fio38-c,
+cert-flp30-c,
+cert-mem57-cpp,
+cert-msc30-c,
+cert-msc32-c,
+cert-msc50-cpp,
+cert-msc51-cpp,
+cert-oop11-cpp,
+cert-oop54-cpp,
+cert-oop57-cpp,
+modernize-avoid-bind,
+modernize-deprecated-headers,
+modernize-deprecated-ios-base-aliases,
+modernize-loop-convert,
+modernize-make-shared,
+modernize-make-unique,
+modernize-raw-string-literal,
+modernize-replace-auto-ptr,
+modernize-replace-random-shuffle,
+modernize-return-braced-init-list,
+modernize-shrink-to-fit,
+modernize-unary-static-assert,
+modernize-use-bool-literals,
+modernize-use-default-member-init,
+modernize-use-emplace,
+modernize-use-equals-default,
+modernize-use-equals-delete,
+modernize-use-noexcept,
+modernize-use-nullptr,
+modernize-use-override,
+modernize-use-transparent-functors,
+modernize-use-uncaught-exceptions,
+modernize-use-using,
+bugprone-argument-comment,
+bugprone-assert-side-effect,
+bugprone-bad-signal-to-kill-thread,
+bugprone-bool-pointer-implicit-conversion,
+bugprone-branch-clone,
+bugprone-copy-constructor-init,
+bugprone-dangling-handle,
+bugprone-dynamic-static-initializers,
+bugprone-fold-init-type,
+bugprone-forward-declaration-namespace,
+bugprone-forwarding-reference-overload,
+bugprone-inaccurate-erase,
+bugprone-incorrect-roundings,
+bugprone-infinite-loop,
+bugprone-integer-division,
+bugprone-lambda-function-name,
+bugprone-macro-parentheses,
+bugprone-macro-repeated-side-effects,
+bugprone-misplaced-operator-in-strlen-in-alloc,
+bugprone-misplaced-pointer-arithmetic-in-alloc,
+bugprone-misplaced-widening-cast,
+bugprone-multiple-statement-macro,
+bugprone-narrowing-conversions,
+bugprone-no-escape,
+bugprone-not-null-terminated-result,
+bugprone-parent-virtual-call,
+bugprone-posix-return,
+bugprone-reserved-identifier,
+bugprone-signed-char-misuse,
+bugprone-sizeof-container,
+bugprone-sizeof-expression,
+bugprone-spuriously-wake-up-functions,
+bugprone-string-constructor,
+bugprone-string-integer-assignment,
+bugprone-string-literal-with-embedded-nul,
+bugprone-suspicious-enum-usage,
+bugprone-suspicious-include,
+bugprone-suspicious-memset-usage,
+bugprone-suspicious-missing-comma,
+bugprone-suspicious-semicolon,
+bugprone-suspicious-string-compare,
+bugprone-swapped-arguments,
+bugprone-terminating-continue,
+bugprone-throw-keyword-missing,
+bugprone-too-small-loop-variable,
+bugprone-undefined-memory-manipulation,
+bugprone-undelegated-constructor,
+bugprone-unhandled-self-assignment,
+bugprone-unused-raii,
+bugprone-unused-return-value,
+bugprone-use-after-move,
+bugprone-virtual-near-miss,
+misc-misplaced-const,
+misc-no-recursion,
+misc-redundant-expression,
+misc-static-assert,
+misc-throw-by-value-catch-by-reference,
+misc-unconventional-assign-operator,
+misc-uniqueptr-reset-release,
+misc-unused-using-decls,
+performance-for-range-copy,
+performance-implicit-conversion-in-loop,
+performance-inefficient-algorithm,
+performance-inefficient-vector-operation,
+performance-move-constructor-init,
+performance-no-automatic-move,
+performance-trivially-destructible,
+performance-type-promotion-in-math-fn,
+performance-unnecessary-copy-initialization,
+readability-identifier-naming,
+readability-braces-around-statements,
+readability-const-return-type,
+readability-delete-null-pointer,
+readability-deleted-default,
+readability-else-after-return'
+
+
+WarningsAsErrors: '*'
HeaderFilterRegex: '.*'
CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
diff --git a/http/http_client.hpp b/http/http_client.hpp
index 93c2a60..cc30cab 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -222,16 +222,13 @@
state = ConnState::terminated;
return;
}
- else if (retryPolicyAction == "SuspendRetries")
+ if (retryPolicyAction == "SuspendRetries")
{
state = ConnState::suspended;
return;
}
- else
- {
- // keep retrying, reset count and continue.
- retryCount = 0;
- }
+ // keep retrying, reset count and continue.
+ retryCount = 0;
}
if ((state == ConnState::connectFailed) ||
@@ -265,11 +262,8 @@
});
return;
}
- else
- {
- // reset retry count.
- retryCount = 0;
- }
+ // reset retry count.
+ retryCount = 0;
connStateCheck();
return;
diff --git a/http/http_request.h b/http/http_request.h
index 10aabc3..c3e497f 100644
--- a/http/http_request.h
+++ b/http/http_request.h
@@ -42,37 +42,37 @@
return req.method();
}
- const std::string_view getHeaderValue(std::string_view key) const
+ std::string_view getHeaderValue(std::string_view key) const
{
return req[key];
}
- const std::string_view getHeaderValue(boost::beast::http::field key) const
+ std::string_view getHeaderValue(boost::beast::http::field key) const
{
return req[key];
}
- const std::string_view methodString() const
+ std::string_view methodString() const
{
return req.method_string();
}
- const std::string_view target() const
+ std::string_view target() const
{
return req.target();
}
- unsigned version()
+ unsigned version() const
{
return req.version();
}
- bool isUpgrade()
+ bool isUpgrade() const
{
return boost::beast::websocket::is_upgrade(req);
}
- bool keepAlive()
+ bool keepAlive() const
{
return req.keep_alive();
}
diff --git a/http/routing.h b/http/routing.h
index b49e15e..52d1b06 100644
--- a/http/routing.h
+++ b/http/routing.h
@@ -40,7 +40,9 @@
std::unique_ptr<BaseRule> upgrade()
{
if (ruleToUpgrade)
+ {
return std::move(ruleToUpgrade);
+ }
return {};
}
@@ -660,12 +662,16 @@
for (size_t x : node->paramChildrens)
{
if (!x)
+ {
continue;
+ }
Node* child = &nodes[x];
optimizeNode(child);
}
if (node->children.empty())
+ {
return;
+ }
bool mergeWithChild = true;
for (const std::pair<std::string, unsigned>& kv : node->children)
{
@@ -710,8 +716,10 @@
void validate()
{
if (!head()->isSimpleNode())
+ {
throw std::runtime_error(
"Internal error: Trie header should be simple!");
+ }
optimize();
}
@@ -754,15 +762,21 @@
{
RoutingParams empty;
if (params == nullptr)
+ {
params = ∅
+ }
unsigned found{};
RoutingParams matchParams;
if (node == nullptr)
+ {
node = head();
+ }
if (pos == req_url.size())
+ {
return {node->ruleIndex, *params};
+ }
auto updateFound =
[&found, &matchParams](std::pair<unsigned, RoutingParams>& ret) {
@@ -847,7 +861,9 @@
for (; epos < req_url.size(); epos++)
{
if (req_url[epos] == '/')
+ {
break;
+ }
}
if (epos != pos)
@@ -948,7 +964,9 @@
}
}
if (nodes[idx].ruleIndex)
+ {
throw std::runtime_error("handler already exists for " + url);
+ }
nodes[idx].ruleIndex = ruleIndex;
}
@@ -1085,7 +1103,9 @@
{
std::unique_ptr<BaseRule> upgraded = rule->upgrade();
if (upgraded)
+ {
rule = std::move(upgraded);
+ }
rule->validate();
internalAddRuleObject(rule->rule, rule.get());
}
@@ -1121,7 +1141,9 @@
}
if (ruleIndex >= rules.size())
+ {
throw std::runtime_error("Trie internal structure corrupted!");
+ }
if (ruleIndex == ruleSpecialRedirectSlash)
{
@@ -1223,7 +1245,9 @@
}
if (ruleIndex >= rules.size())
+ {
throw std::runtime_error("Trie internal structure corrupted!");
+ }
if (ruleIndex == ruleSpecialRedirectSlash)
{
diff --git a/include/authorization.hpp b/include/authorization.hpp
index 24dbb7b..634620b 100644
--- a/include/authorization.hpp
+++ b/include/authorization.hpp
@@ -34,7 +34,7 @@
}
}
-static const std::shared_ptr<persistent_data::UserSession>
+static std::shared_ptr<persistent_data::UserSession>
performBasicAuth(std::string_view auth_header)
{
BMCWEB_LOG_DEBUG << "[AuthMiddleware] Basic authentication";
@@ -79,7 +79,7 @@
isConfigureSelfOnly);
}
-static const std::shared_ptr<persistent_data::UserSession>
+static std::shared_ptr<persistent_data::UserSession>
performTokenAuth(std::string_view auth_header)
{
BMCWEB_LOG_DEBUG << "[AuthMiddleware] Token authentication";
@@ -90,7 +90,7 @@
return session;
}
-static const std::shared_ptr<persistent_data::UserSession>
+static std::shared_ptr<persistent_data::UserSession>
performXtokenAuth(const crow::Request& req)
{
BMCWEB_LOG_DEBUG << "[AuthMiddleware] X-Auth-Token authentication";
@@ -105,7 +105,7 @@
return session;
}
-static const std::shared_ptr<persistent_data::UserSession>
+static std::shared_ptr<persistent_data::UserSession>
performCookieAuth(const crow::Request& req)
{
BMCWEB_LOG_DEBUG << "[AuthMiddleware] Cookie authentication";
@@ -130,7 +130,7 @@
std::string_view authKey =
cookieValue.substr(startIndex, endIndex - startIndex);
- const std::shared_ptr<persistent_data::UserSession> session =
+ std::shared_ptr<persistent_data::UserSession> session =
persistent_data::SessionStore::getInstance().loginSessionByToken(
authKey);
if (session == nullptr)
@@ -163,7 +163,7 @@
}
#ifdef BMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION
-static const std::shared_ptr<persistent_data::UserSession>
+static std::shared_ptr<persistent_data::UserSession>
performTLSAuth(const crow::Request& req, Response& res,
std::weak_ptr<persistent_data::UserSession> session)
{
@@ -176,24 +176,19 @@
<< " will be used for this request.";
return sp;
}
- else
+ std::string_view cookieValue = req.getHeaderValue("Cookie");
+ if (cookieValue.empty() ||
+ cookieValue.find("SESSION=") == std::string::npos)
{
- std::string_view cookieValue = req.getHeaderValue("Cookie");
- if (cookieValue.empty() ||
- cookieValue.find("SESSION=") == std::string::npos)
- {
- // TODO: change this to not switch to cookie auth
- res.addHeader(
- "Set-Cookie",
- "XSRF-TOKEN=" + sp->csrfToken +
- "; Secure\r\nSet-Cookie: SESSION=" + sp->sessionToken +
- "; Secure; HttpOnly\r\nSet-Cookie: "
- "IsAuthenticated=true; Secure");
- BMCWEB_LOG_DEBUG
- << " TLS session: " << sp->uniqueId
- << " with cookie will be used for this request.";
- return sp;
- }
+ // TODO: change this to not switch to cookie auth
+ res.addHeader("Set-Cookie", "XSRF-TOKEN=" + sp->csrfToken +
+ "; Secure\r\nSet-Cookie: SESSION=" +
+ sp->sessionToken +
+ "; Secure; HttpOnly\r\nSet-Cookie: "
+ "IsAuthenticated=true; Secure");
+ BMCWEB_LOG_DEBUG << " TLS session: " << sp->uniqueId
+ << " with cookie will be used for this request.";
+ return sp;
}
}
return nullptr;
diff --git a/include/http_utility.hpp b/include/http_utility.hpp
index e0166e3..d282a28 100644
--- a/include/http_utility.hpp
+++ b/include/http_utility.hpp
@@ -19,7 +19,7 @@
{
return true;
}
- else if (encoding == "application/json")
+ if (encoding == "application/json")
{
return false;
}
diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp
index f6719c7..b897fa7 100644
--- a/include/ibm/locks.hpp
+++ b/include/ibm/locks.hpp
@@ -317,20 +317,16 @@
BMCWEB_LOG_DEBUG << "Not a Valid request id";
return std::make_pair(false, status);
}
- else
+ // Validation passed, check if all the locks are owned by the
+ // requesting HMC
+ auto status2 = isItMyLock(p, ids);
+ if (status2.first)
{
- // Validation passed, check if all the locks are owned by the
- // requesting HMC
- auto status = isItMyLock(p, ids);
- if (status.first)
- {
- // The current hmc owns all the locks, so we can release
- // them
- releaseLock(p);
- }
- return std::make_pair(true, status);
+ // The current hmc owns all the locks, so we can release
+ // them
+ releaseLock(p);
}
- return std::make_pair(false, status);
+ return std::make_pair(true, status);
}
inline RcAcquireLock Lock::acquireLock(const LockRequests lockRequestStructure)
@@ -358,19 +354,14 @@
BMCWEB_LOG_DEBUG << "There is a conflict within itself";
return std::make_pair(true, std::make_pair(status, 1));
}
- else
- {
- BMCWEB_LOG_DEBUG << "The request is not conflicting within itself";
+ BMCWEB_LOG_DEBUG << "The request is not conflicting within itself";
- // Need to check for conflict with the locktable entries.
+ // Need to check for conflict with the locktable entries.
- auto conflict = isConflictWithTable(multiRequest);
+ auto conflict = isConflictWithTable(multiRequest);
- BMCWEB_LOG_DEBUG << "Done with checking conflict with the locktable";
- return std::make_pair(false, conflict);
- }
-
- return std::make_pair(true, std::make_pair(true, 1));
+ BMCWEB_LOG_DEBUG << "Done with checking conflict with the locktable";
+ return std::make_pair(false, conflict);
}
inline void Lock::releaseLock(const ListOfTransactionIds& refRids)
@@ -562,43 +553,38 @@
saveLocks();
return std::make_pair(false, transactionId);
}
+ BMCWEB_LOG_DEBUG
+ << "Lock table is not empty, check for conflict with lock table";
+ // Lock table is not empty, compare the lockrequest entries with
+ // the entries in the lock table
- else
+ for (const auto& lockRecord1 : refLockRequestStructure)
{
- BMCWEB_LOG_DEBUG
- << "Lock table is not empty, check for conflict with lock table";
- // Lock table is not empty, compare the lockrequest entries with
- // the entries in the lock table
-
- for (const auto& lockRecord1 : refLockRequestStructure)
+ for (const auto& map : lockTable)
{
- for (const auto& map : lockTable)
+ for (const auto& lockRecord2 : map.second)
{
- for (const auto& lockRecord2 : map.second)
+ bool status = isConflictRecord(lockRecord1, lockRecord2);
+ if (status)
{
- bool status = isConflictRecord(lockRecord1, lockRecord2);
- if (status)
- {
- return std::make_pair(
- true, std::make_pair(map.first, lockRecord2));
- }
+ return std::make_pair(
+ true, std::make_pair(map.first, lockRecord2));
}
}
}
-
- // Reached here, so no conflict with the locktable, so we are safe to
- // add the request records into the lock table
-
- // Lock table is empty, so we are safe to add the lockrecords
- // as there will be no conflict
- BMCWEB_LOG_DEBUG << " Adding elements into lock table";
- transactionId = generateTransactionId();
- lockTable.emplace(
- std::make_pair(transactionId, refLockRequestStructure));
-
- // save the lock in the persistent file
- saveLocks();
}
+
+ // Reached here, so no conflict with the locktable, so we are safe to
+ // add the request records into the lock table
+
+ // Lock table is empty, so we are safe to add the lockrecords
+ // as there will be no conflict
+ BMCWEB_LOG_DEBUG << " Adding elements into lock table";
+ transactionId = generateTransactionId();
+ lockTable.emplace(std::make_pair(transactionId, refLockRequestStructure));
+
+ // save the lock in the persistent file
+ saveLocks();
return std::make_pair(false, transactionId);
}
@@ -615,25 +601,22 @@
return false;
}
- else
+ BMCWEB_LOG_DEBUG
+ << "There are multiple lock requests coming in a single request";
+
+ // There are multiple requests a part of one request
+
+ for (uint32_t i = 0; i < refLockRequestStructure.size(); i++)
{
- BMCWEB_LOG_DEBUG
- << "There are multiple lock requests coming in a single request";
-
- // There are multiple requests a part of one request
-
- for (uint32_t i = 0; i < refLockRequestStructure.size(); i++)
+ for (uint32_t j = i + 1; j < refLockRequestStructure.size(); j++)
{
- for (uint32_t j = i + 1; j < refLockRequestStructure.size(); j++)
- {
- const LockRequest& p = refLockRequestStructure[i];
- const LockRequest& q = refLockRequestStructure[j];
- bool status = isConflictRecord(p, q);
+ const LockRequest& p = refLockRequestStructure[i];
+ const LockRequest& q = refLockRequestStructure[j];
+ bool status = isConflictRecord(p, q);
- if (status)
- {
- return true;
- }
+ if (status)
+ {
+ return true;
}
}
}
@@ -661,11 +644,6 @@
return false;
}
- else
- {
- return true;
- }
-
return true;
}
@@ -681,69 +659,64 @@
return false;
}
- else
+ uint32_t i = 0;
+ for (const auto& p : std::get<4>(refLockRecord1))
{
- uint32_t i = 0;
- for (const auto& p : std::get<4>(refLockRecord1))
+
+ // return conflict when any of them is try to lock all resources
+ // under the current resource level.
+ if (boost::equals(p.first, "LockAll") ||
+ boost::equals(std::get<4>(refLockRecord2)[i].first, "LockAll"))
{
+ BMCWEB_LOG_DEBUG
+ << "Either of the Comparing locks are trying to lock all "
+ "resources under the current resource level";
+ return true;
+ }
- // return conflict when any of them is try to lock all resources
- // under the current resource level.
- if (boost::equals(p.first, "LockAll") ||
- boost::equals(std::get<4>(refLockRecord2)[i].first, "LockAll"))
+ // determine if there is a lock-all-with-same-segment-size.
+ // If the current segment sizes are the same,then we should fail.
+
+ if ((boost::equals(p.first, "LockSame") ||
+ boost::equals(std::get<4>(refLockRecord2)[i].first, "LockSame")) &&
+ (p.second == std::get<4>(refLockRecord2)[i].second))
+ {
+ return true;
+ }
+
+ // if segment lengths are not the same, it means two different locks
+ // So no conflict
+ if (p.second != std::get<4>(refLockRecord2)[i].second)
+ {
+ BMCWEB_LOG_DEBUG << "Segment lengths are not same";
+ BMCWEB_LOG_DEBUG << "Segment 1 length : " << p.second;
+ BMCWEB_LOG_DEBUG << "Segment 2 length : "
+ << std::get<4>(refLockRecord2)[i].second;
+ return false;
+ }
+
+ // compare segment data
+
+ for (uint32_t i = 0; i < p.second; i++)
+ {
+ // if the segment data is different , then the locks is on a
+ // different resource So no conflict between the lock
+ // records.
+ // BMC is little endian , but the resourceID is formed by
+ // the Management Console in such a way that, the first byte
+ // from the MSB Position corresponds to the First Segment
+ // data. Therefore we need to convert the in-comming
+ // resourceID into Big Endian before processing further.
+ if (!(checkByte(
+ boost::endian::endian_reverse(std::get<3>(refLockRecord1)),
+ boost::endian::endian_reverse(std::get<3>(refLockRecord2)),
+ i)))
{
- BMCWEB_LOG_DEBUG
- << "Either of the Comparing locks are trying to lock all "
- "resources under the current resource level";
- return true;
- }
-
- // determine if there is a lock-all-with-same-segment-size.
- // If the current segment sizes are the same,then we should fail.
-
- if ((boost::equals(p.first, "LockSame") ||
- boost::equals(std::get<4>(refLockRecord2)[i].first,
- "LockSame")) &&
- (p.second == std::get<4>(refLockRecord2)[i].second))
- {
- return true;
- }
-
- // if segment lengths are not the same, it means two different locks
- // So no conflict
- if (p.second != std::get<4>(refLockRecord2)[i].second)
- {
- BMCWEB_LOG_DEBUG << "Segment lengths are not same";
- BMCWEB_LOG_DEBUG << "Segment 1 length : " << p.second;
- BMCWEB_LOG_DEBUG << "Segment 2 length : "
- << std::get<4>(refLockRecord2)[i].second;
return false;
}
-
- // compare segment data
-
- for (uint32_t i = 0; i < p.second; i++)
- {
- // if the segment data is different , then the locks is on a
- // different resource So no conflict between the lock
- // records.
- // BMC is little endian , but the resourceID is formed by
- // the Management Console in such a way that, the first byte
- // from the MSB Position corresponds to the First Segment
- // data. Therefore we need to convert the in-comming
- // resourceID into Big Endian before processing further.
- if (!(checkByte(boost::endian::endian_reverse(
- std::get<3>(refLockRecord1)),
- boost::endian::endian_reverse(
- std::get<3>(refLockRecord2)),
- i)))
- {
- return false;
- }
- }
-
- ++i;
}
+
+ ++i;
}
return false;
diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp
index 2c45693..b0e57ed 100644
--- a/include/ibm/management_console_rest.hpp
+++ b/include/ibm/management_console_rest.hpp
@@ -91,10 +91,7 @@
res.jsonValue["Description"] = contentNotAcceptableMsg;
return;
}
- else
- {
- BMCWEB_LOG_DEBUG << "Not a multipart/form-data. Continue..";
- }
+ BMCWEB_LOG_DEBUG << "Not a multipart/form-data. Continue..";
BMCWEB_LOG_DEBUG
<< "handleIbmPut: Request to create/update the save-area file";
@@ -109,7 +106,7 @@
std::filesystem::path loc("/var/lib/obmc/bmc-console-mgmt/save-area");
loc /= fileID;
- std::string data = std::move(req.body);
+ const std::string& data = req.body;
BMCWEB_LOG_DEBUG << "data capaticty : " << data.capacity();
if (data.capacity() > maxSaveareaFileSize)
{
@@ -133,27 +130,24 @@
res.jsonValue["Description"] = "Error while creating the file";
return;
}
+ file << data;
+ std::string origin = "/ibm/v1/Host/ConfigFiles/" + fileID;
+ // Push an event
+ if (fileExists)
+ {
+ BMCWEB_LOG_DEBUG << "config file is updated";
+ res.jsonValue["Description"] = "File Updated";
+
+ redfish::EventServiceManager::getInstance().sendEvent(
+ redfish::messages::resourceChanged(), origin, "IBMConfigFile");
+ }
else
{
- file << data;
- std::string origin = "/ibm/v1/Host/ConfigFiles/" + fileID;
- // Push an event
- if (fileExists)
- {
- BMCWEB_LOG_DEBUG << "config file is updated";
- res.jsonValue["Description"] = "File Updated";
+ BMCWEB_LOG_DEBUG << "config file is created";
+ res.jsonValue["Description"] = "File Created";
- redfish::EventServiceManager::getInstance().sendEvent(
- redfish::messages::resourceChanged(), origin, "IBMConfigFile");
- }
- else
- {
- BMCWEB_LOG_DEBUG << "config file is created";
- res.jsonValue["Description"] = "File Created";
-
- redfish::EventServiceManager::getInstance().sendEvent(
- redfish::messages::resourceCreated(), origin, "IBMConfigFile");
- }
+ redfish::EventServiceManager::getInstance().sendEvent(
+ redfish::messages::resourceCreated(), origin, "IBMConfigFile");
}
}
@@ -165,7 +159,7 @@
{
for (const auto& file : std::filesystem::directory_iterator(loc))
{
- std::filesystem::path pathObj(file.path());
+ const std::filesystem::path& pathObj = file.path();
pathObjList.push_back("/ibm/v1/Host/ConfigFiles/" +
pathObj.filename().string());
}
@@ -257,6 +251,7 @@
std::ifstream fileOpen(filePath.c_str());
if (static_cast<bool>(fileOpen))
+ {
if (remove(filePath.c_str()) == 0)
{
BMCWEB_LOG_DEBUG << "File removed!\n";
@@ -268,6 +263,7 @@
res.result(boost::beast::http::status::internal_server_error);
res.jsonValue["Description"] = internalServerError;
}
+ }
else
{
BMCWEB_LOG_ERROR << "File not found!\n";
@@ -429,33 +425,30 @@
res.end();
return;
}
- else
+ BMCWEB_LOG_DEBUG << "There is a conflict with the lock table";
+ res.result(boost::beast::http::status::conflict);
+ auto var =
+ std::get<std::pair<uint32_t, LockRequest>>(conflictStatus.second);
+ nlohmann::json returnJson, segments;
+ nlohmann::json myarray = nlohmann::json::array();
+ returnJson["TransactionID"] = var.first;
+ returnJson["SessionID"] = std::get<0>(var.second);
+ returnJson["HMCID"] = std::get<1>(var.second);
+ returnJson["LockType"] = std::get<2>(var.second);
+ returnJson["ResourceID"] = std::get<3>(var.second);
+
+ for (auto& i : std::get<4>(var.second))
{
- BMCWEB_LOG_DEBUG << "There is a conflict with the lock table";
- res.result(boost::beast::http::status::conflict);
- auto var = std::get<std::pair<uint32_t, LockRequest>>(
- conflictStatus.second);
- nlohmann::json returnJson, segments;
- nlohmann::json myarray = nlohmann::json::array();
- returnJson["TransactionID"] = var.first;
- returnJson["SessionID"] = std::get<0>(var.second);
- returnJson["HMCID"] = std::get<1>(var.second);
- returnJson["LockType"] = std::get<2>(var.second);
- returnJson["ResourceID"] = std::get<3>(var.second);
-
- for (auto& i : std::get<4>(var.second))
- {
- segments["LockFlag"] = i.first;
- segments["SegmentLength"] = i.second;
- myarray.push_back(segments);
- }
-
- returnJson["SegmentFlags"] = myarray;
-
- res.jsonValue["Record"] = returnJson;
- res.end();
- return;
+ segments["LockFlag"] = i.first;
+ segments["SegmentLength"] = i.second;
+ myarray.push_back(segments);
}
+
+ returnJson["SegmentFlags"] = myarray;
+
+ res.jsonValue["Record"] = returnJson;
+ res.end();
+ return;
}
}
inline void handleRelaseAllAPI(const crow::Request& req, crow::Response& res)
@@ -490,47 +483,41 @@
res.end();
return;
}
- else
+ auto statusRelease =
+ std::get<crow::ibm_mc_lock::RcRelaseLock>(varReleaselock.second);
+ if (statusRelease.first)
{
- auto statusRelease =
- std::get<crow::ibm_mc_lock::RcRelaseLock>(varReleaselock.second);
- if (statusRelease.first)
- {
- // The current hmc owns all the locks, so we already released
- // them
- res.result(boost::beast::http::status::ok);
- res.end();
- return;
- }
-
- else
- {
- // valid rid, but the current hmc does not own all the locks
- BMCWEB_LOG_DEBUG << "Current HMC does not own all the locks";
- res.result(boost::beast::http::status::unauthorized);
-
- auto var = statusRelease.second;
- nlohmann::json returnJson, segments;
- nlohmann::json myArray = nlohmann::json::array();
- returnJson["TransactionID"] = var.first;
- returnJson["SessionID"] = std::get<0>(var.second);
- returnJson["HMCID"] = std::get<1>(var.second);
- returnJson["LockType"] = std::get<2>(var.second);
- returnJson["ResourceID"] = std::get<3>(var.second);
-
- for (auto& i : std::get<4>(var.second))
- {
- segments["LockFlag"] = i.first;
- segments["SegmentLength"] = i.second;
- myArray.push_back(segments);
- }
-
- returnJson["SegmentFlags"] = myArray;
- res.jsonValue["Record"] = returnJson;
- res.end();
- return;
- }
+ // The current hmc owns all the locks, so we already released
+ // them
+ res.result(boost::beast::http::status::ok);
+ res.end();
+ return;
}
+
+ // valid rid, but the current hmc does not own all the locks
+ BMCWEB_LOG_DEBUG << "Current HMC does not own all the locks";
+ res.result(boost::beast::http::status::unauthorized);
+
+ auto var = statusRelease.second;
+ nlohmann::json returnJson, segments;
+ nlohmann::json myArray = nlohmann::json::array();
+ returnJson["TransactionID"] = var.first;
+ returnJson["SessionID"] = std::get<0>(var.second);
+ returnJson["HMCID"] = std::get<1>(var.second);
+ returnJson["LockType"] = std::get<2>(var.second);
+ returnJson["ResourceID"] = std::get<3>(var.second);
+
+ for (auto& i : std::get<4>(var.second))
+ {
+ segments["LockFlag"] = i.first;
+ segments["SegmentLength"] = i.second;
+ myArray.push_back(segments);
+ }
+
+ returnJson["SegmentFlags"] = myArray;
+ res.jsonValue["Record"] = returnJson;
+ res.end();
+ return;
}
inline void handleGetLockListAPI(crow::Response& res,
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 6bb09d0..2c801c7 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -823,7 +823,7 @@
}
const std::string& keyType = codes[0];
const std::string& valueType = codes[1];
- for (auto it : j->items())
+ for (const auto& it : j->items())
{
r = convertJsonToDbus(m, keyType, it.key());
if (r < 0)
@@ -1453,10 +1453,7 @@
}
return;
}
- else
- {
- transaction->methodPassed = true;
- }
+ transaction->methodPassed = true;
handleMethodResponse(transaction, m2,
returnType);
@@ -2146,7 +2143,7 @@
.methods(boost::beast::http::verb::get)([](const crow::Request&,
crow::Response& res,
const std::string& dumpId) {
- std::regex validFilename("^[\\w\\- ]+(\\.?[\\w\\- ]*)$");
+ std::regex validFilename(R"(^[\w\- ]+(\.?[\w\- ]*)$)");
if (!std::regex_match(dumpId, validFilename))
{
res.result(boost::beast::http::status::bad_request);
@@ -2250,7 +2247,7 @@
// causes the normal trailing backslash redirector to
// fail.
}
- else if (!it->empty())
+ if (!it->empty())
{
objectPath += "/" + *it;
}
diff --git a/include/ssl_key_handler.hpp b/include/ssl_key_handler.hpp
index deb3a76..19d3ec7 100644
--- a/include/ssl_key_handler.hpp
+++ b/include/ssl_key_handler.hpp
@@ -32,10 +32,7 @@
{
return true;
}
- else
- {
- return false;
- }
+ return false;
}
inline bool validateCertificate(X509* const cert)
@@ -85,12 +82,9 @@
<< X509_verify_cert_error_string(errCode);
return true;
}
- else
- {
- BMCWEB_LOG_ERROR << "Certificate verification failed. Reason: "
- << X509_verify_cert_error_string(errCode);
- return false;
- }
+ BMCWEB_LOG_ERROR << "Certificate verification failed. Reason: "
+ << X509_verify_cert_error_string(errCode);
+ return false;
}
BMCWEB_LOG_ERROR
diff --git a/include/webassets.hpp b/include/webassets.hpp
index 9944dfd..c2a6851 100644
--- a/include/webassets.hpp
+++ b/include/webassets.hpp
@@ -65,7 +65,7 @@
for (const std::filesystem::directory_entry& dir : paths)
{
- std::filesystem::path absolutePath = dir.path();
+ const std::filesystem::path& absolutePath = dir.path();
std::filesystem::path relativePath{
absolutePath.string().substr(rootpath.string().size() - 1)};
if (std::filesystem::is_directory(dir))
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index d29d9c6..21b25e4 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -1064,7 +1064,7 @@
// send everything.
if (entry->resourceTypes.size())
{
- for (auto resource : entry->resourceTypes)
+ for (const auto& resource : entry->resourceTypes)
{
if (resType == resource)
{
diff --git a/redfish-core/include/privileges.hpp b/redfish-core/include/privileges.hpp
index 2d44545..c3a88d5 100644
--- a/redfish-core/include/privileges.hpp
+++ b/redfish-core/include/privileges.hpp
@@ -213,24 +213,21 @@
"ConfigureUsers", "ConfigureComponents"};
return admin;
}
- else if (userRole == "priv-operator")
+ if (userRole == "priv-operator")
{
// Redfish privilege : Operator
static Privileges op{"Login", "ConfigureSelf", "ConfigureComponents"};
return op;
}
- else if (userRole == "priv-user")
+ if (userRole == "priv-user")
{
// Redfish privilege : Readonly
static Privileges readOnly{"Login", "ConfigureSelf"};
return readOnly;
}
- else
- {
- // Redfish privilege : NoAccess
- static Privileges noaccess;
- return noaccess;
- }
+ // Redfish privilege : NoAccess
+ static Privileges noaccess;
+ return noaccess;
}
/**
diff --git a/redfish-core/include/utils/fw_utils.hpp b/redfish-core/include/utils/fw_utils.hpp
index 0750b43..5554d3b 100644
--- a/redfish-core/include/utils/fw_utils.hpp
+++ b/redfish-core/include/utils/fw_utils.hpp
@@ -284,21 +284,18 @@
{
return "Enabled";
}
- else if (fwState == "xyz.openbmc_project.Software.Activation."
- "Activations.Activating")
+ if (fwState == "xyz.openbmc_project.Software.Activation."
+ "Activations.Activating")
{
return "Updating";
}
- else if (fwState == "xyz.openbmc_project.Software.Activation."
- "Activations.StandbySpare")
+ if (fwState == "xyz.openbmc_project.Software.Activation."
+ "Activations.StandbySpare")
{
return "StandbySpare";
}
- else
- {
- BMCWEB_LOG_DEBUG << "Default fw state " << fwState << " to Disabled";
- return "Disabled";
- }
+ BMCWEB_LOG_DEBUG << "Default fw state " << fwState << " to Disabled";
+ return "Disabled";
}
/**
@@ -321,11 +318,8 @@
{
return "OK";
}
- else
- {
- BMCWEB_LOG_DEBUG << "FW state " << fwState << " to Warning";
- return "Warning";
- }
+ BMCWEB_LOG_DEBUG << "FW state " << fwState << " to Warning";
+ return "Warning";
}
/**
diff --git a/redfish-core/include/utils/systemd_utils.hpp b/redfish-core/include/utils/systemd_utils.hpp
index 0db1d94..75bbe35 100644
--- a/redfish-core/include/utils/systemd_utils.hpp
+++ b/redfish-core/include/utils/systemd_utils.hpp
@@ -29,7 +29,7 @@
* @return Service root UUID
*/
-inline const std::string getUuid()
+inline std::string getUuid()
{
std::string ret;
// This ID needs to match the one in ipmid
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index 897c5c4..266843e 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -83,15 +83,15 @@
{
return "Administrator";
}
- else if (role == "priv-user")
+ if (role == "priv-user")
{
return "ReadOnly";
}
- else if (role == "priv-operator")
+ if (role == "priv-operator")
{
return "Operator";
}
- else if ((role == "") || (role == "priv-noaccess"))
+ if ((role == "") || (role == "priv-noaccess"))
{
return "NoAccess";
}
@@ -103,15 +103,15 @@
{
return "priv-admin";
}
- else if (role == "ReadOnly")
+ if (role == "ReadOnly")
{
return "priv-user";
}
- else if (role == "Operator")
+ if (role == "Operator")
{
return "priv-operator";
}
- else if ((role == "NoAccess") || (role == ""))
+ if ((role == "NoAccess") || (role == ""))
{
return "priv-noaccess";
}
@@ -185,7 +185,7 @@
{"GroupsAttribute", confData.groupAttribute}}}}},
};
- json_response[ldapType].update(std::move(ldap));
+ json_response[ldapType].update(ldap);
nlohmann::json& roleMapArray = json_response[ldapType]["RemoteRoleMapping"];
roleMapArray = nlohmann::json::array();
@@ -365,7 +365,7 @@
{"RemoteGroup", *remoteGroup}});
},
ldapDbusService, dbusObjectPath, ldapPrivMapperInterface,
- "Create", std::move(*remoteGroup),
+ "Create", *remoteGroup,
getPrivilegeFromRoleId(std::move(*localRole)));
}
}
@@ -1731,28 +1731,25 @@
locked);
return;
}
- else
- {
- crow::connections::systemBus->async_method_call(
- [this, asyncResp, username, password(std::move(password)),
- roleId(std::move(roleId)), enabled(std::move(enabled)),
- newUser{std::string(*newUserName)},
- locked(std::move(locked))](const boost::system::error_code ec,
- sdbusplus::message::message& m) {
- if (ec)
- {
- userErrorMessageHandler(m.get_error(), asyncResp,
- newUser, username);
- return;
- }
+ crow::connections::systemBus->async_method_call(
+ [this, asyncResp, username, password(std::move(password)),
+ roleId(std::move(roleId)), enabled(std::move(enabled)),
+ newUser{std::string(*newUserName)},
+ locked(std::move(locked))](const boost::system::error_code ec,
+ sdbusplus::message::message& m) {
+ if (ec)
+ {
+ userErrorMessageHandler(m.get_error(), asyncResp, newUser,
+ username);
+ return;
+ }
- updateUserProperties(asyncResp, newUser, password, enabled,
- roleId, locked);
- },
- "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
- "xyz.openbmc_project.User.Manager", "RenameUser", username,
- *newUserName);
- }
+ updateUserProperties(asyncResp, newUser, password, enabled,
+ roleId, locked);
+ },
+ "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
+ "xyz.openbmc_project.User.Manager", "RenameUser", username,
+ *newUserName);
}
void updateUserProperties(std::shared_ptr<AsyncResp> asyncResp,
diff --git a/redfish-core/lib/cpudimm.hpp b/redfish-core/lib/cpudimm.hpp
index e670037..e4b7a9d 100644
--- a/redfish-core/lib/cpudimm.hpp
+++ b/redfish-core/lib/cpudimm.hpp
@@ -103,11 +103,8 @@
// HTTP Code will be set up automatically, just return
return;
}
- else
- {
- aResp->res.jsonValue["Status"]["State"] = "Enabled";
- present = true;
- }
+ aResp->res.jsonValue["Status"]["State"] = "Enabled";
+ present = true;
aResp->res.jsonValue["TotalCores"] = *coresCount;
}
else if (property.first == "Socket")
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 3494ede..1fb8783 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -158,11 +158,11 @@
{
return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both";
}
- else if (isIPv4)
+ if (isIPv4)
{
return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4";
}
- else if (isIPv6)
+ if (isIPv6)
{
return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6";
}
@@ -183,10 +183,7 @@
{
return "IPv4LinkLocal";
}
- else
- {
- return "LinkLocal";
- }
+ return "LinkLocal";
}
if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP")
{
@@ -194,10 +191,7 @@
{
return "DHCP";
}
- else
- {
- return "DHCPv6";
- }
+ return "DHCPv6";
}
if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.SLAAC")
{
@@ -678,10 +672,7 @@
// Continuity not preserved
return false;
}
- else
- {
- (*bits)++;
- }
+ (*bits)++;
}
else
{
@@ -1567,12 +1558,9 @@
messages::resourceCannotBeDeleted(asyncResp->res);
return;
}
- else
- {
- messages::propertyValueFormatError(
- asyncResp->res, thisJson.dump(), pathString);
- return;
- }
+ messages::propertyValueFormatError(
+ asyncResp->res, thisJson.dump(), pathString);
+ return;
}
if (thisJson.is_null())
@@ -1704,12 +1692,9 @@
messages::resourceCannotBeDeleted(asyncResp->res);
return;
}
- else
- {
- messages::propertyValueFormatError(
- asyncResp->res, thisJson.dump(), pathString);
- return;
- }
+ messages::propertyValueFormatError(
+ asyncResp->res, thisJson.dump(), pathString);
+ return;
}
if (thisJson.is_null())
@@ -2099,10 +2084,7 @@
{
return false;
}
- else
- {
- return true;
- }
+ return true;
}
/**
diff --git a/redfish-core/lib/health.hpp b/redfish-core/lib/health.hpp
index 4f21b3e..19175e7 100644
--- a/redfish-core/lib/health.hpp
+++ b/redfish-core/lib/health.hpp
@@ -122,8 +122,8 @@
rollup = "Critical";
return;
}
- else if (boost::starts_with(path.str, globalInventoryPath) &&
- boost::ends_with(path.str, "warning"))
+ if (boost::starts_with(path.str, globalInventoryPath) &&
+ boost::ends_with(path.str, "warning"))
{
health = "Warning";
if (rollup != "Critical")
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 777f37e..1198455 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -114,13 +114,13 @@
{
return "Critical";
}
- else if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") ||
- (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") ||
- (s == "xyz.openbmc_project.Logging.Entry.Level.Notice"))
+ if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") ||
+ (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") ||
+ (s == "xyz.openbmc_project.Logging.Entry.Level.Notice"))
{
return "OK";
}
- else if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
+ if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
{
return "Warning";
}
@@ -789,8 +789,8 @@
"DiagnosticDataType & OEMDiagnosticDataType");
return;
}
- else if ((*oemDiagnosticDataType != "System") ||
- (*diagnosticDataType != "OEM"))
+ if ((*oemDiagnosticDataType != "System") ||
+ (*diagnosticDataType != "OEM"))
{
BMCWEB_LOG_ERROR << "Wrong parameter values passed";
messages::invalidObject(asyncResp->res,
@@ -808,7 +808,7 @@
asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
return;
}
- else if (*diagnosticDataType != "Manager")
+ if (*diagnosticDataType != "Manager")
{
BMCWEB_LOG_ERROR
<< "Wrong parameter value passed for 'DiagnosticDataType'";
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 213237c..2da7f3a 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -133,21 +133,18 @@
doBMCGracefulRestart(asyncResp);
return;
}
- else if (resetType == "ForceRestart")
+ if (resetType == "ForceRestart")
{
BMCWEB_LOG_DEBUG << "Proceeding with " << resetType;
doBMCForceRestart(asyncResp);
return;
}
- else
- {
- BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
- << resetType;
- messages::actionParameterNotSupported(asyncResp->res, resetType,
- "ResetType");
+ BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
+ << resetType;
+ messages::actionParameterNotSupported(asyncResp->res, resetType,
+ "ResetType");
- return;
- }
+ return;
}
};
@@ -1611,7 +1608,7 @@
{
return;
}
- else if (ret == CreatePIDRet::del)
+ if (ret == CreatePIDRet::del)
{
continue;
}
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index 8ee617f..8752cf8 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -265,7 +265,8 @@
for (auto& unit : r)
{
/* Only traverse through <xyz>.socket units */
- std::string unitName = std::get<NET_PROTO_UNIT_NAME>(unit);
+ const std::string& unitName =
+ std::get<NET_PROTO_UNIT_NAME>(unit);
if (!boost::ends_with(unitName, ".socket"))
{
continue;
@@ -280,9 +281,9 @@
continue;
}
const char* rfServiceKey = kv.first;
- std::string socketPath =
+ const std::string& socketPath =
std::get<NET_PROTO_UNIT_OBJ_PATH>(unit);
- std::string unitState =
+ const std::string& unitState =
std::get<NET_PROTO_UNIT_SUB_STATE>(unit);
asyncResp->res
diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp
index 21ec6dc..19438af 100644
--- a/redfish-core/lib/pcie.hpp
+++ b/redfish-core/lib/pcie.hpp
@@ -45,7 +45,7 @@
pcieDeviceList = nlohmann::json::array();
for (const std::string& pcieDevicePath : pcieDevicePaths)
{
- size_t devStart = pcieDevicePath.rfind("/");
+ size_t devStart = pcieDevicePath.rfind('/');
if (devStart == std::string::npos)
{
continue;
diff --git a/redfish-core/lib/roles.hpp b/redfish-core/lib/roles.hpp
index 610c086..de2e1ff 100644
--- a/redfish-core/lib/roles.hpp
+++ b/redfish-core/lib/roles.hpp
@@ -28,15 +28,15 @@
{
return "Administrator";
}
- else if (priv == "priv-user")
+ if (priv == "priv-user")
{
return "ReadOnly";
}
- else if (priv == "priv-operator")
+ if (priv == "priv-operator")
{
return "Operator";
}
- else if (priv == "priv-noaccess")
+ if (priv == "priv-noaccess")
{
return "NoAccess";
}
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index ac98735..91e54bb 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -304,9 +304,7 @@
auto objectsWithConnectionCb =
[callback](const boost::container::flat_set<std::string>& connections,
const std::set<std::pair<std::string, std::string>>&
- /*objectsWithConnection*/) {
- callback(std::move(connections));
- };
+ /*objectsWithConnection*/) { callback(connections); };
getObjectsWithConnection(SensorsAsyncResp, sensorNames,
std::move(objectsWithConnectionCb));
}
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 34202b1..3f74ca5 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -351,7 +351,9 @@
std::get_if<uint64_t>(
&property.second);
if (nullptr != procFamily)
+ {
break;
+ }
continue;
}
@@ -361,7 +363,9 @@
std::get_if<std::string>(
&property.second);
if (nullptr != processorId)
+ {
break;
+ }
continue;
}
}
@@ -670,30 +674,25 @@
{
return "None";
}
- else if (dbusSource ==
- "xyz.openbmc_project.Control.Boot.Source.Sources.Disk")
+ if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk")
{
return "Hdd";
}
- else if (dbusSource ==
- "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia")
+ if (dbusSource ==
+ "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia")
{
return "Cd";
}
- else if (dbusSource ==
- "xyz.openbmc_project.Control.Boot.Source.Sources.Network")
+ if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network")
{
return "Pxe";
}
- else if (dbusSource ==
- "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia")
+ if (dbusSource ==
+ "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia")
{
return "Usb";
}
- else
- {
- return "";
- }
+ return "";
}
/**
@@ -710,18 +709,15 @@
{
return "None";
}
- else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe")
+ if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe")
{
return "Diags";
}
- else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup")
+ if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup")
{
return "BiosSetup";
}
- else
- {
- return "";
- }
+ return "";
}
/**
@@ -747,7 +743,7 @@
{
return 0;
}
- else if (rfSource == "Pxe")
+ if (rfSource == "Pxe")
{
bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network";
}
@@ -1482,17 +1478,15 @@
{
return "None";
}
- else if (dbusAction ==
- "xyz.openbmc_project.State.Watchdog.Action.HardReset")
+ if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset")
{
return "ResetSystem";
}
- else if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff")
+ if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff")
{
return "PowerDown";
}
- else if (dbusAction ==
- "xyz.openbmc_project.State.Watchdog.Action.PowerCycle")
+ if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle")
{
return "PowerCycle";
}
@@ -1515,15 +1509,15 @@
{
return "xyz.openbmc_project.State.Watchdog.Action.None";
}
- else if (rfAction == "PowerCycle")
+ if (rfAction == "PowerCycle")
{
return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle";
}
- else if (rfAction == "PowerDown")
+ if (rfAction == "PowerDown")
{
return "xyz.openbmc_project.State.Watchdog.Action.PowerOff";
}
- else if (rfAction == "ResetSystem")
+ if (rfAction == "ResetSystem")
{
return "xyz.openbmc_project.State.Watchdog.Action.HardReset";
}
diff --git a/redfish-core/ut/lock_test.cpp b/redfish-core/ut/lock_test.cpp
index 08ba27a..5c68cdc 100644
--- a/redfish-core/ut/lock_test.cpp
+++ b/redfish-core/ut/lock_test.cpp
@@ -59,8 +59,8 @@
234,
{{"LockAll", 2}, {"DontLock", 4}}}};
}
- ~LockTest()
- {}
+
+ ~LockTest() override = default;
};
class MockLock : public crow::ibm_mc_lock::Lock