From 289873744aec61b189ea4731060e8dcac86c044b Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 8 Apr 2022 05:21:04 -1000 Subject: [PATCH] Apply clang-tidy readability-else-after-return (#17125) * Apply clang-tidy readability-else-after-return * Apply changes from mac * Restyle * Fix some wrongly added whitespace in comments and log strings * Restyle * One more pass at removing else after return - this seems to be incremental * One more pass at removing else after return - this seems to be incremental * One more pass on darwin of running tidy fix * Restyle * Remove odd error usage in CommissioneeShellCommands.cpp * Remove odd error usage in ControllerShellCommands.cpp * Take out return from PUBLISH_RECORDS * Restyle * Add 2 more fixes for else after return * Restyle --- .clang-tidy | 2 +- examples/bridge-app/linux/main.cpp | 2 +- .../commands/clusters/CustomArgument.h | 8 +- .../chip-tool/commands/common/CHIPCommand.cpp | 6 +- .../chip-tool/commands/common/Command.cpp | 34 ++- .../linux/CommissioneeShellCommands.cpp | 17 +- .../linux/ControllerShellCommands.cpp | 23 +- .../linux/LinuxCommissionableDataProvider.cpp | 2 +- examples/platform/linux/Options.cpp | 3 +- examples/shell/shell_common/cmd_ping.cpp | 6 +- .../account-login/AccountLoginManager.cpp | 8 +- examples/tv-casting-app/linux/main.cpp | 13 +- src/app/EventManagement.cpp | 8 +- .../barrier-control-server.cpp | 8 +- src/app/clusters/bindings/bindings.cpp | 2 +- .../color-control-server.cpp | 93 ++++---- .../door-lock-server/door-lock-server.cpp | 14 +- .../clusters/groups-server/groups-server.cpp | 20 +- .../identify-server/identify-server.cpp | 2 +- .../localization-configuration-server.cpp | 6 +- .../operational-credentials-server.cpp | 18 +- .../clusters/ota-requestor/BDXDownloader.cpp | 8 +- .../ota-requestor/DefaultOTARequestor.cpp | 2 +- .../ota-requestor/DefaultOTARequestor.h | 6 +- .../DefaultOTARequestorDriver.cpp | 13 +- src/app/clusters/scenes/scenes.cpp | 218 +++++++++--------- .../test-cluster-server.cpp | 48 ++-- .../thermostat-server/thermostat-server.cpp | 76 +++--- .../user-label-server/user-label-server.cpp | 8 +- src/app/tests/TestReadInteraction.cpp | 6 +- src/app/tests/integration/MockEvents.cpp | 6 +- .../commissioner/CommissionerCommands.cpp | 14 +- src/app/util/attribute-storage.cpp | 6 +- src/app/util/util.cpp | 44 ++-- src/controller/AutoCommissioner.cpp | 22 +- src/controller/CHIPDeviceController.cpp | 16 +- .../ChipDeviceController-StorageDelegate.cpp | 12 +- src/controller/tests/TestWriteChunking.cpp | 8 +- src/controller/tests/data_model/TestRead.cpp | 88 ++++--- src/controller/tests/data_model/TestWrite.cpp | 2 +- src/darwin/Framework/CHIP/CHIPSetupPayload.mm | 18 +- .../platform/KvsPersistentStorageDelegate.h | 8 +- .../AddressResolve_DefaultImpl.cpp | 8 +- src/lib/dnssd/Discovery_ImplPlatform.cpp | 29 +-- src/lib/shell/commands/BLE.cpp | 6 +- src/lib/shell/commands/Config.cpp | 6 +- src/lib/shell/commands/OnboardingCodes.cpp | 16 +- src/lib/shell/commands/WiFi.cpp | 2 +- .../support/TestPersistentStorageDelegate.h | 26 +-- src/lib/support/tests/TestStateMachine.cpp | 18 +- .../Darwin/BleConnectionDelegateImpl.mm | 6 +- src/platform/Darwin/DnssdImpl.cpp | 34 ++- src/platform/Darwin/UUIDHelperImpl.mm | 11 +- src/platform/Linux/DeviceInfoProviderImpl.cpp | 18 +- src/protocols/secure_channel/CASESession.cpp | 2 +- src/tools/chip-cert/Cmd_GenAttCert.cpp | 5 +- src/tools/spake2p/Cmd_GenVerifier.cpp | 4 +- src/transport/SecureSessionTable.h | 6 +- 58 files changed, 495 insertions(+), 626 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 2e2dc36e1717ac..08060772cbfc65 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,4 +1,4 @@ --- -Checks: 'modernize-use-nullptr,bugprone-*,-bugprone-not-null-terminated-result,-bugprone-suspicious-memory-comparison,-bugprone-argument-comment,-bugprone-unused-return-value,-bugprone-branch-clone,-bugprone-easily-swappable-parameters,-bugprone-reserved-identifier,-bugprone-macro-parentheses,-bugprone-forward-declaration-namespace,-bugprone-forwarding-reference-overload,-bugprone-undelegated-constructor,-bugprone-sizeof-expression,-bugprone-implicit-widening-of-multiplication-result,-bugprone-too-small-loop-variable,-bugprone-narrowing-conversions,-bugprone-misplaced-widening-cast,-bugprone-suspicious-include,-bugprone-signed-char-misuse,-bugprone-copy-constructor-init,-clang-analyzer-core.CallAndMessage,-clang-analyzer-core.UndefinedBinaryOperatorResult,-clang-analyzer-core.NullDereference,-clang-analyzer-optin.cplusplus.UninitializedObject,-clang-analyzer-core.uninitialized.Branch,-clang-analyzer-optin.performance,-clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,-clang-analyzer-deadcode.DeadStores,-clang-analyzer-cplusplus.Move,-clang-analyzer-optin.cplusplus.VirtualCall,-clang-analyzer-security.insecureAPI.strcpy,-clang-analyzer-nullability.NullablePassedToNonnull,-clang-analyzer-optin.performance.Padding,-clang-analyzer-security.insecureAPI.bzero,-clang-analyzer-unix.cstring.NullArg,-clang-analyzer-security.insecureAPI.rand,-clang-analyzer-core.NonNullParamChecker,-clang-analyzer-nullability.NullPassedToNonnull,-clang-analyzer-unix.Malloc,-clang-analyzer-valist.Unterminated,-clang-analyzer-cplusplus.NewDeleteLeaks,-clang-diagnostic-implicit-int-conversion' +Checks: 'readability-else-after-return,modernize-use-nullptr,bugprone-*,-bugprone-not-null-terminated-result,-bugprone-suspicious-memory-comparison,-bugprone-argument-comment,-bugprone-unused-return-value,-bugprone-branch-clone,-bugprone-easily-swappable-parameters,-bugprone-reserved-identifier,-bugprone-macro-parentheses,-bugprone-forward-declaration-namespace,-bugprone-forwarding-reference-overload,-bugprone-undelegated-constructor,-bugprone-sizeof-expression,-bugprone-implicit-widening-of-multiplication-result,-bugprone-too-small-loop-variable,-bugprone-narrowing-conversions,-bugprone-misplaced-widening-cast,-bugprone-suspicious-include,-bugprone-signed-char-misuse,-bugprone-copy-constructor-init,-clang-analyzer-core.CallAndMessage,-clang-analyzer-core.UndefinedBinaryOperatorResult,-clang-analyzer-core.NullDereference,-clang-analyzer-optin.cplusplus.UninitializedObject,-clang-analyzer-core.uninitialized.Branch,-clang-analyzer-optin.performance,-clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,-clang-analyzer-deadcode.DeadStores,-clang-analyzer-cplusplus.Move,-clang-analyzer-optin.cplusplus.VirtualCall,-clang-analyzer-security.insecureAPI.strcpy,-clang-analyzer-nullability.NullablePassedToNonnull,-clang-analyzer-optin.performance.Padding,-clang-analyzer-security.insecureAPI.bzero,-clang-analyzer-unix.cstring.NullArg,-clang-analyzer-security.insecureAPI.rand,-clang-analyzer-core.NonNullParamChecker,-clang-analyzer-nullability.NullPassedToNonnull,-clang-analyzer-unix.Malloc,-clang-analyzer-valist.Unterminated,-clang-analyzer-cplusplus.NewDeleteLeaks,-clang-diagnostic-implicit-int-conversion' WarningsAsErrors: '*' HeaderFilterRegex: '(src|examples|zzz_generated|credentials)' diff --git a/examples/bridge-app/linux/main.cpp b/examples/bridge-app/linux/main.cpp index eaabbfbaf3ec73..02e92e87146693 100644 --- a/examples/bridge-app/linux/main.cpp +++ b/examples/bridge-app/linux/main.cpp @@ -225,7 +225,7 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span= min && *value <= max); } - else - { - return false; - } + + return false; }); break; } @@ -409,10 +405,8 @@ bool Command::InitArgument(size_t argIndex, char * argValue) int64_t max = chip::CanCastTo(arg.max) ? static_cast(arg.max) : INT64_MAX; return (!ss.fail() && ss.eof() && *value >= min && *value <= max); } - else - { - return false; - } + + return false; }); break; } diff --git a/examples/platform/linux/CommissioneeShellCommands.cpp b/examples/platform/linux/CommissioneeShellCommands.cpp index e256cb0fbecb72..a07a6bb4e31489 100644 --- a/examples/platform/linux/CommissioneeShellCommands.cpp +++ b/examples/platform/linux/CommissioneeShellCommands.cpp @@ -79,8 +79,6 @@ static CHIP_ERROR PrintAllCommands() static CHIP_ERROR CommissioneeHandler(int argc, char ** argv) { - CHIP_ERROR error = CHIP_NO_ERROR; - if (argc == 0 || strcmp(argv[0], "help") == 0) { return PrintAllCommands(); @@ -92,10 +90,10 @@ static CHIP_ERROR CommissioneeHandler(int argc, char ** argv) chip::Inet::IPAddress commissioner; chip::Inet::IPAddress::FromString(argv[1], commissioner); uint16_t port = (uint16_t) strtol(argv[2], &eptr, 10); - return error = SendUDC(true, chip::Transport::PeerAddress::UDP(commissioner, port)); + return SendUDC(true, chip::Transport::PeerAddress::UDP(commissioner, port)); } #endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT - else if (strcmp(argv[0], "setdiscoverytimeout") == 0) + if (strcmp(argv[0], "setdiscoverytimeout") == 0) { char * eptr; int16_t timeout = (int16_t) strtol(argv[1], &eptr, 10); @@ -111,7 +109,7 @@ static CHIP_ERROR CommissioneeHandler(int argc, char ** argv) return CHIP_NO_ERROR; } #endif // CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY - else if (strcmp(argv[0], "restartmdns") == 0) + if (strcmp(argv[0], "restartmdns") == 0) { if (argc < 2) { @@ -127,18 +125,15 @@ static CHIP_ERROR CommissioneeHandler(int argc, char ** argv) chip::app::DnssdServer::Instance().StartServer(chip::Dnssd::CommissioningMode::kEnabledBasic); return CHIP_NO_ERROR; } - else if (strcmp(argv[1], "enabled_enhanced") == 0) + if (strcmp(argv[1], "enabled_enhanced") == 0) { chip::app::DnssdServer::Instance().StartServer(chip::Dnssd::CommissioningMode::kEnabledEnhanced); return CHIP_NO_ERROR; } return PrintAllCommands(); } - else - { - return CHIP_ERROR_INVALID_ARGUMENT; - } - return error; + + return CHIP_ERROR_INVALID_ARGUMENT; } void RegisterCommissioneeCommands() diff --git a/examples/platform/linux/ControllerShellCommands.cpp b/examples/platform/linux/ControllerShellCommands.cpp index 81d21ece09ae16..7d580e61dba48f 100644 --- a/examples/platform/linux/ControllerShellCommands.cpp +++ b/examples/platform/linux/ControllerShellCommands.cpp @@ -202,8 +202,6 @@ static CHIP_ERROR PrintAllCommands() static CHIP_ERROR ControllerHandler(int argc, char ** argv) { - CHIP_ERROR error = CHIP_NO_ERROR; - if (argc == 0 || strcmp(argv[0], "help") == 0) { return PrintAllCommands(); @@ -211,25 +209,25 @@ static CHIP_ERROR ControllerHandler(int argc, char ** argv) #if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY else if (strcmp(argv[0], "udc-reset") == 0) { - return error = ResetUDC(true); + return ResetUDC(true); } else if (strcmp(argv[0], "udc-print") == 0) { - return error = PrintUDC(true); + return PrintUDC(true); } #endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE else if (strcmp(argv[0], "discover-commissionable") == 0) { - return error = discover(true); + return discover(true); } else if (strcmp(argv[0], "discover-commissionable-instance") == 0) { - return error = discover(true, argv[1]); + return discover(true, argv[1]); } else if (strcmp(argv[0], "discover-display") == 0) { - return error = display(true); + return display(true); } else if (strcmp(argv[0], "commission-onnetwork") == 0) { @@ -247,7 +245,7 @@ static CHIP_ERROR ControllerHandler(int argc, char ** argv) uint16_t port = (uint16_t) strtol(argv[4], &eptr, 10); - return error = pairOnNetwork(true, pincode, disc, Transport::PeerAddress::UDP(address, port)); + return pairOnNetwork(true, pincode, disc, Transport::PeerAddress::UDP(address, port)); } else if (strcmp(argv[0], "ux") == 0) { @@ -289,14 +287,11 @@ static CHIP_ERROR ControllerHandler(int argc, char ** argv) char * eptr; uint32_t pincode = (uint32_t) strtol(argv[1], &eptr, 10); size_t index = (size_t) strtol(argv[2], &eptr, 10); - return error = pairUDC(true, pincode, index); + return pairUDC(true, pincode, index); } #endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE - else - { - return CHIP_ERROR_INVALID_ARGUMENT; - } - return error; + + return CHIP_ERROR_INVALID_ARGUMENT; } void RegisterControllerCommands() diff --git a/examples/platform/linux/LinuxCommissionableDataProvider.cpp b/examples/platform/linux/LinuxCommissionableDataProvider.cpp index 7733d99c3ca860..4d978abaf79ecc 100644 --- a/examples/platform/linux/LinuxCommissionableDataProvider.cpp +++ b/examples/platform/linux/LinuxCommissionableDataProvider.cpp @@ -94,7 +94,7 @@ CHIP_ERROR LinuxCommissionableDataProvider::Init(chip::Optional(spake2pSaltLength)); return CHIP_ERROR_INVALID_ARGUMENT; } - else if (!havePaseSalt) + if (!havePaseSalt) { ChipLogProgress(Support, "LinuxCommissionableDataProvider didn't get a PASE salt, generating one."); std::vector spake2pSaltVector; diff --git a/examples/platform/linux/Options.cpp b/examples/platform/linux/Options.cpp index fabf4dc1b84137..5a85fe629a683d 100644 --- a/examples/platform/linux/Options.cpp +++ b/examples/platform/linux/Options.cpp @@ -321,8 +321,7 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier, retval = false; break; } - else if ((iterCount < chip::Crypto::kSpake2p_Min_PBKDF_Iterations) || - (iterCount > chip::Crypto::kSpake2p_Max_PBKDF_Iterations)) + if ((iterCount < chip::Crypto::kSpake2p_Min_PBKDF_Iterations) || (iterCount > chip::Crypto::kSpake2p_Max_PBKDF_Iterations)) { PrintArgError("%s: ERROR: argument %s not in range [%zu, %zu]\n", aProgram, aName, chip::Crypto::kSpake2p_Min_PBKDF_Iterations, chip::Crypto::kSpake2p_Max_PBKDF_Iterations); diff --git a/examples/shell/shell_common/cmd_ping.cpp b/examples/shell/shell_common/cmd_ping.cpp index 878672a6e042b4..6d9a0782fcff09 100644 --- a/examples/shell/shell_common/cmd_ping.cpp +++ b/examples/shell/shell_common/cmd_ping.cpp @@ -140,12 +140,10 @@ Transport::PeerAddress GetEchoPeerAddress() { return Transport::PeerAddress::TCP(gDestAddr, gPingArguments.GetEchoPort()); } - else + #endif - { - return Transport::PeerAddress::UDP(gDestAddr, gPingArguments.GetEchoPort(), ::chip::Inet::InterfaceId::Null()); - } + return Transport::PeerAddress::UDP(gDestAddr, gPingArguments.GetEchoPort(), ::chip::Inet::InterfaceId::Null()); } void Shutdown() diff --git a/examples/tv-app/linux/include/account-login/AccountLoginManager.cpp b/examples/tv-app/linux/include/account-login/AccountLoginManager.cpp index edf79a5367ed91..7a27ce2d3660f6 100644 --- a/examples/tv-app/linux/include/account-login/AccountLoginManager.cpp +++ b/examples/tv-app/linux/include/account-login/AccountLoginManager.cpp @@ -40,11 +40,9 @@ bool AccountLoginManager::HandleLogin(const CharSpan & tempAccountIdentifier, co ChipLogProgress(Zcl, "AccountLoginManager::HandleLogin success"); return true; } - else - { - ChipLogProgress(Zcl, "AccountLoginManager::HandleLogin failed expected pin %s", mSetupPin); - return false; - } + + ChipLogProgress(Zcl, "AccountLoginManager::HandleLogin failed expected pin %s", mSetupPin); + return false; } bool AccountLoginManager::HandleLogout() diff --git a/examples/tv-casting-app/linux/main.cpp b/examples/tv-casting-app/linux/main.cpp index d6491ade593911..d7957cd1e22f23 100644 --- a/examples/tv-casting-app/linux/main.cpp +++ b/examples/tv-casting-app/linux/main.cpp @@ -86,17 +86,16 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, gDiscoveryFilter = Dnssd::DiscoveryFilter(Dnssd::DiscoveryFilterType::kDeviceType, static_cast(deviceType)); return true; } - else + + for (int i = 0; i < kKnownDeviceTypesCount; i++) { - for (int i = 0; i < kKnownDeviceTypesCount; i++) + if (strcasecmp(aValue, kKnownDeviceTypes[i].name) == 0) { - if (strcasecmp(aValue, kKnownDeviceTypes[i].name) == 0) - { - gDiscoveryFilter = Dnssd::DiscoveryFilter(Dnssd::DiscoveryFilterType::kDeviceType, kKnownDeviceTypes[i].id); - return true; - } + gDiscoveryFilter = Dnssd::DiscoveryFilter(Dnssd::DiscoveryFilterType::kDeviceType, kKnownDeviceTypes[i].id); + return true; } } + ChipLogError(AppServer, "%s: INTERNAL ERROR: Unhandled option value: %s %s", aProgram, aName, aValue); return false; } diff --git a/src/app/EventManagement.cpp b/src/app/EventManagement.cpp index ad657d819ddb7a..6cb20a2f6efc49 100644 --- a/src/app/EventManagement.cpp +++ b/src/app/EventManagement.cpp @@ -405,15 +405,13 @@ CHIP_ERROR EventManagement::CopyAndAdjustDeltaTime(const TLVReader & aReader, si return ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp)), ctx->mpContext->mCurrentTime.mValue - ctx->mpContext->mPreviousTime.mValue); } - else if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kEpochTimestamp))) && !(ctx->mpContext->mFirst)) + if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kEpochTimestamp))) && !(ctx->mpContext->mFirst)) { return ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaEpochTimestamp)), ctx->mpContext->mCurrentTime.mValue - ctx->mpContext->mPreviousTime.mValue); } - else - { - return ctx->mpWriter->CopyElement(reader); - } + + return ctx->mpWriter->CopyElement(reader); } void EventManagement::VendEventNumber() diff --git a/src/app/clusters/barrier-control-server/barrier-control-server.cpp b/src/app/clusters/barrier-control-server/barrier-control-server.cpp index 4ba04852cfb2d8..60117fb82ec238 100644 --- a/src/app/clusters/barrier-control-server/barrier-control-server.cpp +++ b/src/app/clusters/barrier-control-server/barrier-control-server.cpp @@ -235,11 +235,9 @@ static uint32_t calculateDelayMs(EndpointId endpoint, uint8_t targetPosition, bo { return MIN_POSITION_CHANGE_DELAY_MS; } - else - { - uint32_t delayMs = openOrClosePeriodMs / positionDelta; - return (delayMs < MIN_POSITION_CHANGE_DELAY_MS ? MIN_POSITION_CHANGE_DELAY_MS : delayMs); - } + + uint32_t delayMs = openOrClosePeriodMs / positionDelta; + return (delayMs < MIN_POSITION_CHANGE_DELAY_MS ? MIN_POSITION_CHANGE_DELAY_MS : delayMs); } void emberAfBarrierControlClusterServerTickCallback(EndpointId endpoint) diff --git a/src/app/clusters/bindings/bindings.cpp b/src/app/clusters/bindings/bindings.cpp index 98103b494e8a38..a3b10c27f39bd5 100644 --- a/src/app/clusters/bindings/bindings.cpp +++ b/src/app/clusters/bindings/bindings.cpp @@ -196,7 +196,7 @@ CHIP_ERROR BindingTableAccess::WriteBindingTable(const ConcreteDataAttributePath LogErrorOnFailure(NotifyBindingsChanged()); return CHIP_NO_ERROR; } - else if (path.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) + if (path.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) { TargetStructType target; ReturnErrorOnFailure(decoder.Decode(target)); diff --git a/src/app/clusters/color-control-server/color-control-server.cpp b/src/app/clusters/color-control-server/color-control-server.cpp index b7c105c5d774ae..9cad7eb03884fb 100644 --- a/src/app/clusters/color-control-server/color-control-server.cpp +++ b/src/app/clusters/color-control-server/color-control-server.cpp @@ -174,11 +174,9 @@ void ColorControlServer::handleModeSwitch(EndpointId endpoint, uint8_t newColorM { return; } - else - { - Attributes::EnhancedColorMode::Set(endpoint, newColorMode); - Attributes::ColorMode::Set(endpoint, newColorMode); - } + + Attributes::EnhancedColorMode::Set(endpoint, newColorMode); + Attributes::ColorMode::Set(endpoint, newColorMode); colorModeTransition = static_cast((newColorMode << 4) + oldColorMode); @@ -673,63 +671,62 @@ bool ColorControlServer::computeNewHueValue(ColorControlServer::ColorHueTransiti // we are performing a move to and not a move. return true; } + + // Check if we are in a color loop. If not, we are in a moveHue + uint8_t isColorLoop = 0; + Attributes::ColorLoopActive::Get(p->endpoint, &isColorLoop); + + if (isColorLoop) + { + p->currentEnhancedHue = p->initialEnhancedHue; + } else { - // Check if we are in a color loop. If not, we are in a moveHue - uint8_t isColorLoop = 0; - Attributes::ColorLoopActive::Get(p->endpoint, &isColorLoop); - - if (isColorLoop) + // we are performing a Hue move. Need to compute the new values for the + // next move period. + if (p->up) { - p->currentEnhancedHue = p->initialEnhancedHue; + if (p->isEnhancedHue) + { + newHue = subtractEnhancedHue(p->finalEnhancedHue, p->initialEnhancedHue); + newHue = addEnhancedHue(p->finalEnhancedHue, newHue); + + p->initialEnhancedHue = p->finalEnhancedHue; + p->finalEnhancedHue = newHue; + } + else + { + newHue = subtractHue(p->finalHue, p->initialHue); + newHue = addHue(p->finalHue, static_cast(newHue)); + + p->initialHue = p->finalHue; + p->finalHue = static_cast(newHue); + } } else { - // we are performing a Hue move. Need to compute the new values for the - // next move period. - if (p->up) + if (p->isEnhancedHue) { - if (p->isEnhancedHue) - { - newHue = subtractEnhancedHue(p->finalEnhancedHue, p->initialEnhancedHue); - newHue = addEnhancedHue(p->finalEnhancedHue, newHue); - - p->initialEnhancedHue = p->finalEnhancedHue; - p->finalEnhancedHue = newHue; - } - else - { - newHue = subtractHue(p->finalHue, p->initialHue); - newHue = addHue(p->finalHue, static_cast(newHue)); - - p->initialHue = p->finalHue; - p->finalHue = static_cast(newHue); - } + newHue = subtractEnhancedHue(p->initialEnhancedHue, p->finalEnhancedHue); + newHue = subtractEnhancedHue(p->finalEnhancedHue, newHue); + + p->initialEnhancedHue = p->finalEnhancedHue; + p->finalEnhancedHue = newHue; } else { - if (p->isEnhancedHue) - { - newHue = subtractEnhancedHue(p->initialEnhancedHue, p->finalEnhancedHue); - newHue = subtractEnhancedHue(p->finalEnhancedHue, newHue); - - p->initialEnhancedHue = p->finalEnhancedHue; - p->finalEnhancedHue = newHue; - } - else - { - newHue = subtractHue(p->initialHue, p->finalHue); - newHue = subtractHue(p->finalHue, static_cast(newHue)); - - p->initialHue = p->finalHue; - p->finalHue = static_cast(newHue); - } + newHue = subtractHue(p->initialHue, p->finalHue); + newHue = subtractHue(p->finalHue, static_cast(newHue)); + + p->initialHue = p->finalHue; + p->finalHue = static_cast(newHue); } } - - p->stepsRemaining = p->stepsTotal; } + + p->stepsRemaining = p->stepsTotal; } + return false; } diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index f0347d9cbd038d..544a633747807a 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -1996,15 +1996,13 @@ DlStatus DoorLockServer::modifyProgrammingPIN(chip::EndpointId endpointId, chip: endpointId, credentialIndex, to_underlying(credentialType), credentialData.size()); return DlStatus::kFailure; } - else - { - emberAfDoorLockClusterPrintln("[SetCredential] Successfully modified the credential " - "[endpointId=%d,credentialIndex=%d,credentialType=%u,credentialDataSize=%zu]", - endpointId, credentialIndex, to_underlying(credentialType), credentialData.size()); - sendRemoteLockUserChange(endpointId, credentialTypeToLockDataType(credentialType), DlDataOperationType::kModify, - sourceNodeId, modifierFabricIndex, relatedUserIndex, credentialIndex); - } + emberAfDoorLockClusterPrintln("[SetCredential] Successfully modified the credential " + "[endpointId=%d,credentialIndex=%d,credentialType=%u,credentialDataSize=%zu]", + endpointId, credentialIndex, to_underlying(credentialType), credentialData.size()); + + sendRemoteLockUserChange(endpointId, credentialTypeToLockDataType(credentialType), DlDataOperationType::kModify, sourceNodeId, + modifierFabricIndex, relatedUserIndex, credentialIndex); return DlStatus::kSuccess; } diff --git a/src/app/clusters/groups-server/groups-server.cpp b/src/app/clusters/groups-server/groups-server.cpp index 0d4ec94ca2a6a3..d766c11fd7bb2a 100644 --- a/src/app/clusters/groups-server/groups-server.cpp +++ b/src/app/clusters/groups-server/groups-server.cpp @@ -92,12 +92,10 @@ static EmberAfStatus GroupAdd(FabricIndex fabricIndex, EndpointId endpointId, Gr { return EMBER_ZCL_STATUS_SUCCESS; } - else - { - ChipLogDetail(Zcl, "ERR: Failed to add mapping (end:%d, group:0x%x), err:%" CHIP_ERROR_FORMAT, endpointId, groupId, - err.Format()); - return EMBER_ZCL_STATUS_INSUFFICIENT_SPACE; - } + + ChipLogDetail(Zcl, "ERR: Failed to add mapping (end:%d, group:0x%x), err:%" CHIP_ERROR_FORMAT, endpointId, groupId, + err.Format()); + return EMBER_ZCL_STATUS_INSUFFICIENT_SPACE; } static EmberAfStatus GroupRemove(FabricIndex fabricIndex, EndpointId endpointId, GroupId groupId) @@ -113,12 +111,10 @@ static EmberAfStatus GroupRemove(FabricIndex fabricIndex, EndpointId endpointId, { return EMBER_ZCL_STATUS_SUCCESS; } - else - { - ChipLogDetail(Zcl, "ERR: Failed to remove mapping (end:%d, group:0x%x), err:%" CHIP_ERROR_FORMAT, endpointId, groupId, - err.Format()); - return EMBER_ZCL_STATUS_NOT_FOUND; - } + + ChipLogDetail(Zcl, "ERR: Failed to remove mapping (end:%d, group:0x%x), err:%" CHIP_ERROR_FORMAT, endpointId, groupId, + err.Format()); + return EMBER_ZCL_STATUS_NOT_FOUND; } void emberAfGroupsClusterServerInitCallback(EndpointId endpointId) diff --git a/src/app/clusters/identify-server/identify-server.cpp b/src/app/clusters/identify-server/identify-server.cpp index ce7805dacd2748..73d723f6b0ca5f 100644 --- a/src/app/clusters/identify-server/identify-server.cpp +++ b/src/app/clusters/identify-server/identify-server.cpp @@ -184,7 +184,7 @@ void MatterIdentifyClusterServerAttributeChangedCallback(const app::ConcreteAttr return; } /* stop identify process */ - else if (EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT == identify->mCurrentEffectIdentifier && identifyTime > 0) + if (EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT == identify->mCurrentEffectIdentifier && identifyTime > 0) { Clusters::Identify::Attributes::IdentifyTime::Set(endpoint, 0); identify_deactivate(identify); diff --git a/src/app/clusters/localization-configuration-server/localization-configuration-server.cpp b/src/app/clusters/localization-configuration-server/localization-configuration-server.cpp index 5063e7378ec219..9679a7aee6ae05 100644 --- a/src/app/clusters/localization-configuration-server/localization-configuration-server.cpp +++ b/src/app/clusters/localization-configuration-server/localization-configuration-server.cpp @@ -198,10 +198,8 @@ void emberAfLocalizationConfigurationClusterServerInitCallback(EndpointId endpoi err = CHIP_ERROR_WRITE_FAILED; break; } - else - { - validLocaleCached = true; - } + + validLocaleCached = true; } } diff --git a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp index 76fb6b532cda36..044bf3cc6eba88 100644 --- a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp +++ b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp @@ -545,27 +545,27 @@ OperationalCertStatus ConvertToNOCResponseStatus(CHIP_ERROR err) { return OperationalCertStatus::kSuccess; } - else if (err == CHIP_ERROR_INVALID_PUBLIC_KEY) + if (err == CHIP_ERROR_INVALID_PUBLIC_KEY) { return OperationalCertStatus::kInvalidPublicKey; } - else if (err == CHIP_ERROR_INVALID_FABRIC_ID || err == CHIP_ERROR_WRONG_NODE_ID) + if (err == CHIP_ERROR_INVALID_FABRIC_ID || err == CHIP_ERROR_WRONG_NODE_ID) { return OperationalCertStatus::kInvalidNodeOpId; } - else if (err == CHIP_ERROR_CA_CERT_NOT_FOUND || err == CHIP_ERROR_CERT_PATH_LEN_CONSTRAINT_EXCEEDED || - err == CHIP_ERROR_CERT_PATH_TOO_LONG || err == CHIP_ERROR_CERT_USAGE_NOT_ALLOWED || err == CHIP_ERROR_CERT_EXPIRED || - err == CHIP_ERROR_CERT_NOT_VALID_YET || err == CHIP_ERROR_UNSUPPORTED_CERT_FORMAT || - err == CHIP_ERROR_UNSUPPORTED_ELLIPTIC_CURVE || err == CHIP_ERROR_CERT_LOAD_FAILED || - err == CHIP_ERROR_CERT_NOT_TRUSTED || err == CHIP_ERROR_WRONG_CERT_DN) + if (err == CHIP_ERROR_CA_CERT_NOT_FOUND || err == CHIP_ERROR_CERT_PATH_LEN_CONSTRAINT_EXCEEDED || + err == CHIP_ERROR_CERT_PATH_TOO_LONG || err == CHIP_ERROR_CERT_USAGE_NOT_ALLOWED || err == CHIP_ERROR_CERT_EXPIRED || + err == CHIP_ERROR_CERT_NOT_VALID_YET || err == CHIP_ERROR_UNSUPPORTED_CERT_FORMAT || + err == CHIP_ERROR_UNSUPPORTED_ELLIPTIC_CURVE || err == CHIP_ERROR_CERT_LOAD_FAILED || err == CHIP_ERROR_CERT_NOT_TRUSTED || + err == CHIP_ERROR_WRONG_CERT_DN) { return OperationalCertStatus::kInvalidNOC; } - else if (err == CHIP_ERROR_NO_MEMORY) + if (err == CHIP_ERROR_NO_MEMORY) { return OperationalCertStatus::kTableFull; } - else if (err == CHIP_ERROR_FABRIC_EXISTS) + if (err == CHIP_ERROR_FABRIC_EXISTS) { return OperationalCertStatus::kFabricConflict; } diff --git a/src/app/clusters/ota-requestor/BDXDownloader.cpp b/src/app/clusters/ota-requestor/BDXDownloader.cpp index 5453ed73b51a13..90f1ecd8e9255c 100644 --- a/src/app/clusters/ota-requestor/BDXDownloader.cpp +++ b/src/app/clusters/ota-requestor/BDXDownloader.cpp @@ -72,11 +72,9 @@ bool BDXDownloader::HasTransferTimedOut() mPrevBlockCounter = curBlockCounter; return false; } - else - { - ChipLogError(BDX, "BDX transfer timeout"); - return true; - } + + ChipLogError(BDX, "BDX transfer timeout"); + return true; } void BDXDownloader::OnMessageReceived(const chip::PayloadHeader & payloadHeader, chip::System::PacketBufferHandle msg) diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp index 728ec17a08be47..eadabe60d14bf4 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp @@ -617,7 +617,7 @@ IdleStateReason DefaultOTARequestor::MapErrorToIdleStateReason(CHIP_ERROR error) { return IdleStateReason::kIdle; } - else if (error == CHIP_ERROR_CONNECTION_CLOSED_UNEXPECTEDLY) + if (error == CHIP_ERROR_CONNECTION_CLOSED_UNEXPECTEDLY) { return IdleStateReason::kInvalidSession; } diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.h b/src/app/clusters/ota-requestor/DefaultOTARequestor.h index 285926335c4d6d..ef42419343f9b5 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestor.h +++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.h @@ -149,10 +149,8 @@ class DefaultOTARequestor : public OTARequestorInterface, public BDXDownloader:: ChipLogError(BDX, "BDXDownloader instance is null, can't pass message"); return CHIP_NO_ERROR; } - else - { - mDownloader->OnMessageReceived(payloadHeader, payload.Retain()); - } + + mDownloader->OnMessageReceived(payloadHeader, payload.Retain()); // For a receiver using BDX Protocol, all received messages will require a response except for a StatusReport if (!payloadHeader.HasMessageType(chip::Protocols::SecureChannel::MsgType::StatusReport)) diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp index 7e44dcbaba1b9a..14387898409a95 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp @@ -115,10 +115,8 @@ bool DefaultOTARequestorDriver::ProviderLocationsEqual(const ProviderLocationTyp { return true; } - else - { - return false; - } + + return false; } void DefaultOTARequestorDriver::HandleError(UpdateFailureState state, CHIP_ERROR error) {} @@ -462,11 +460,8 @@ bool DefaultOTARequestorDriver::GetNextProviderLocation(ProviderLocationType & p listExhausted = true; return true; } - else - { - ChipLogError(SoftwareUpdate, "No suitable OTA Provider candidate found"); - return false; - } + + ChipLogError(SoftwareUpdate, "No suitable OTA Provider candidate found"); return false; } diff --git a/src/app/clusters/scenes/scenes.cpp b/src/app/clusters/scenes/scenes.cpp index 75dd1f91cf67f5..adfe4c4e725949 100644 --- a/src/app/clusters/scenes/scenes.cpp +++ b/src/app/clusters/scenes/scenes.cpp @@ -508,7 +508,7 @@ EmberAfStatus emberAfScenesClusterStoreCurrentSceneCallback(chip::FabricIndex fa index = i; break; } - else if (index == EMBER_AF_SCENE_TABLE_NULL_INDEX && entry.endpoint == EMBER_AF_SCENE_TABLE_UNUSED_ENDPOINT_ID) + if (index == EMBER_AF_SCENE_TABLE_NULL_INDEX && entry.endpoint == EMBER_AF_SCENE_TABLE_UNUSED_ENDPOINT_ID) { index = i; } @@ -622,130 +622,126 @@ EmberAfStatus emberAfScenesClusterRecallSavedSceneCallback(chip::FabricIndex fab { return EMBER_ZCL_STATUS_INVALID_FIELD; } - else + + uint8_t i; + for (i = 0; i < EMBER_AF_PLUGIN_SCENES_TABLE_SIZE; i++) { - uint8_t i; - for (i = 0; i < EMBER_AF_PLUGIN_SCENES_TABLE_SIZE; i++) + EmberAfSceneTableEntry entry; + emberAfPluginScenesServerRetrieveSceneEntry(entry, i); + if (entry.endpoint == endpoint && entry.groupId == groupId && entry.sceneId == sceneId) { - EmberAfSceneTableEntry entry; - emberAfPluginScenesServerRetrieveSceneEntry(entry, i); - if (entry.endpoint == endpoint && entry.groupId == groupId && entry.sceneId == sceneId) - { #ifdef ZCL_USING_ON_OFF_CLUSTER_SERVER - if (entry.hasOnOffValue) - { - writeServerAttribute(endpoint, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, "on/off", - (uint8_t *) &entry.onOffValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE); - } + if (entry.hasOnOffValue) + { + writeServerAttribute(endpoint, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, "on/off", + (uint8_t *) &entry.onOffValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE); + } #endif #ifdef ZCL_USING_LEVEL_CONTROL_CLUSTER_SERVER - if (entry.hasCurrentLevelValue) - { - writeServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID, "current level", - (uint8_t *) &entry.currentLevelValue, ZCL_INT8U_ATTRIBUTE_TYPE); - } + if (entry.hasCurrentLevelValue) + { + writeServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID, "current level", + (uint8_t *) &entry.currentLevelValue, ZCL_INT8U_ATTRIBUTE_TYPE); + } #endif #ifdef ZCL_USING_THERMOSTAT_CLUSTER_SERVER - if (entry.hasOccupiedCoolingSetpointValue) - { - writeServerAttribute(endpoint, ZCL_THERMOSTAT_CLUSTER_ID, ZCL_OCCUPIED_COOLING_SETPOINT_ATTRIBUTE_ID, - "occupied cooling setpoint", (uint8_t *) &entry.occupiedCoolingSetpointValue, - ZCL_INT16S_ATTRIBUTE_TYPE); - } - if (entry.hasOccupiedHeatingSetpointValue) - { - writeServerAttribute(endpoint, ZCL_THERMOSTAT_CLUSTER_ID, ZCL_OCCUPIED_HEATING_SETPOINT_ATTRIBUTE_ID, - "occupied heating setpoint", (uint8_t *) &entry.occupiedHeatingSetpointValue, - ZCL_INT16S_ATTRIBUTE_TYPE); - } - if (entry.hasSystemModeValue) - { - writeServerAttribute(endpoint, ZCL_THERMOSTAT_CLUSTER_ID, ZCL_SYSTEM_MODE_ATTRIBUTE_ID, "system mode", - (uint8_t *) &entry.systemModeValue, ZCL_INT8U_ATTRIBUTE_TYPE); - } + if (entry.hasOccupiedCoolingSetpointValue) + { + writeServerAttribute(endpoint, ZCL_THERMOSTAT_CLUSTER_ID, ZCL_OCCUPIED_COOLING_SETPOINT_ATTRIBUTE_ID, + "occupied cooling setpoint", (uint8_t *) &entry.occupiedCoolingSetpointValue, + ZCL_INT16S_ATTRIBUTE_TYPE); + } + if (entry.hasOccupiedHeatingSetpointValue) + { + writeServerAttribute(endpoint, ZCL_THERMOSTAT_CLUSTER_ID, ZCL_OCCUPIED_HEATING_SETPOINT_ATTRIBUTE_ID, + "occupied heating setpoint", (uint8_t *) &entry.occupiedHeatingSetpointValue, + ZCL_INT16S_ATTRIBUTE_TYPE); + } + if (entry.hasSystemModeValue) + { + writeServerAttribute(endpoint, ZCL_THERMOSTAT_CLUSTER_ID, ZCL_SYSTEM_MODE_ATTRIBUTE_ID, "system mode", + (uint8_t *) &entry.systemModeValue, ZCL_INT8U_ATTRIBUTE_TYPE); + } #endif #ifdef ZCL_USING_COLOR_CONTROL_CLUSTER_SERVER - if (entry.hasCurrentXValue) - { - writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_CURRENT_X_ATTRIBUTE_ID, - "current x", (uint8_t *) &entry.currentXValue, ZCL_INT16U_ATTRIBUTE_TYPE); - } - if (entry.hasCurrentYValue) - { - writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_CURRENT_Y_ATTRIBUTE_ID, - "current y", (uint8_t *) &entry.currentYValue, ZCL_INT16U_ATTRIBUTE_TYPE); - } + if (entry.hasCurrentXValue) + { + writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_CURRENT_X_ATTRIBUTE_ID, "current x", + (uint8_t *) &entry.currentXValue, ZCL_INT16U_ATTRIBUTE_TYPE); + } + if (entry.hasCurrentYValue) + { + writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_CURRENT_Y_ATTRIBUTE_ID, "current y", + (uint8_t *) &entry.currentYValue, ZCL_INT16U_ATTRIBUTE_TYPE); + } - if (entry.hasEnhancedCurrentHueValue) - { - writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, - ZCL_COLOR_CONTROL_ENHANCED_CURRENT_HUE_ATTRIBUTE_ID, "enhanced current hue", - (uint8_t *) &entry.enhancedCurrentHueValue, ZCL_INT16U_ATTRIBUTE_TYPE); - } - if (entry.hasCurrentSaturationValue) - { - writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID, - "current saturation", (uint8_t *) &entry.currentSaturationValue, ZCL_INT8U_ATTRIBUTE_TYPE); - } - if (entry.hasColorLoopActiveValue) - { - writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_COLOR_LOOP_ACTIVE_ATTRIBUTE_ID, - "color loop active", (uint8_t *) &entry.colorLoopActiveValue, ZCL_INT8U_ATTRIBUTE_TYPE); - } - if (entry.hasColorLoopDirectionValue) - { - writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, - ZCL_COLOR_CONTROL_COLOR_LOOP_DIRECTION_ATTRIBUTE_ID, "color loop direction", - (uint8_t *) &entry.colorLoopDirectionValue, ZCL_INT8U_ATTRIBUTE_TYPE); - } - if (entry.hasColorLoopTimeValue) - { - writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_COLOR_LOOP_TIME_ATTRIBUTE_ID, - "color loop time", (uint8_t *) &entry.colorLoopTimeValue, ZCL_INT16U_ATTRIBUTE_TYPE); - } - if (entry.hasColorTemperatureMiredsValue) - { - writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_COLOR_TEMPERATURE_ATTRIBUTE_ID, - "color temp mireds", (uint8_t *) &entry.colorTemperatureMiredsValue, - ZCL_INT16U_ATTRIBUTE_TYPE); - } + if (entry.hasEnhancedCurrentHueValue) + { + writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_ENHANCED_CURRENT_HUE_ATTRIBUTE_ID, + "enhanced current hue", (uint8_t *) &entry.enhancedCurrentHueValue, ZCL_INT16U_ATTRIBUTE_TYPE); + } + if (entry.hasCurrentSaturationValue) + { + writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID, + "current saturation", (uint8_t *) &entry.currentSaturationValue, ZCL_INT8U_ATTRIBUTE_TYPE); + } + if (entry.hasColorLoopActiveValue) + { + writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_COLOR_LOOP_ACTIVE_ATTRIBUTE_ID, + "color loop active", (uint8_t *) &entry.colorLoopActiveValue, ZCL_INT8U_ATTRIBUTE_TYPE); + } + if (entry.hasColorLoopDirectionValue) + { + writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_COLOR_LOOP_DIRECTION_ATTRIBUTE_ID, + "color loop direction", (uint8_t *) &entry.colorLoopDirectionValue, ZCL_INT8U_ATTRIBUTE_TYPE); + } + if (entry.hasColorLoopTimeValue) + { + writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_COLOR_LOOP_TIME_ATTRIBUTE_ID, + "color loop time", (uint8_t *) &entry.colorLoopTimeValue, ZCL_INT16U_ATTRIBUTE_TYPE); + } + if (entry.hasColorTemperatureMiredsValue) + { + writeServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_COLOR_TEMPERATURE_ATTRIBUTE_ID, + "color temp mireds", (uint8_t *) &entry.colorTemperatureMiredsValue, + ZCL_INT16U_ATTRIBUTE_TYPE); + } #endif // ZCL_USING_COLOR_CONTROL_CLUSTER_SERVER #ifdef ZCL_USING_DOOR_LOCK_CLUSTER_SERVER - if (entry.hasLockStateValue) - { - writeServerAttribute(endpoint, ZCL_DOOR_LOCK_CLUSTER_ID, ZCL_LOCK_STATE_ATTRIBUTE_ID, "lock state", - (uint8_t *) &entry.lockStateValue, ZCL_INT8U_ATTRIBUTE_TYPE); - } + if (entry.hasLockStateValue) + { + writeServerAttribute(endpoint, ZCL_DOOR_LOCK_CLUSTER_ID, ZCL_LOCK_STATE_ATTRIBUTE_ID, "lock state", + (uint8_t *) &entry.lockStateValue, ZCL_INT8U_ATTRIBUTE_TYPE); + } #endif #ifdef ZCL_USING_WINDOW_COVERING_CLUSTER_SERVER - if (entry.hasCurrentPositionLiftPercentageValue) - { - writeServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID, - ZCL_WC_CURRENT_POSITION_LIFT_PERCENTAGE_ATTRIBUTE_ID, "CurrentPositionLiftPercentage", - (uint8_t *) &entry.currentPositionLiftPercentageValue, ZCL_INT8U_ATTRIBUTE_TYPE); - } - if (entry.hasCurrentPositionTiltPercentageValue) - { - writeServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID, - ZCL_WC_CURRENT_POSITION_TILT_PERCENTAGE_ATTRIBUTE_ID, "CurrentPositionTiltPercentage", - (uint8_t *) &entry.currentPositionTiltPercentageValue, ZCL_INT8U_ATTRIBUTE_TYPE); - } - if (entry.hasTargetPositionLiftPercent100thsValue) - { - writeServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID, - ZCL_WC_TARGET_POSITION_LIFT_PERCENT100_THS_ATTRIBUTE_ID, "TargetPositionLiftPercent100ths", - (uint8_t *) &entry.targetPositionLiftPercent100thsValue, ZCL_INT16U_ATTRIBUTE_TYPE); - } - if (entry.hasTargetPositionTiltPercent100thsValue) - { - writeServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID, - ZCL_WC_TARGET_POSITION_TILT_PERCENT100_THS_ATTRIBUTE_ID, "TargetPositionTiltPercent100ths", - (uint8_t *) &entry.targetPositionTiltPercent100thsValue, ZCL_INT16U_ATTRIBUTE_TYPE); - } -#endif - emberAfScenesMakeValid(endpoint, sceneId, groupId); - return EMBER_ZCL_STATUS_SUCCESS; + if (entry.hasCurrentPositionLiftPercentageValue) + { + writeServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID, ZCL_WC_CURRENT_POSITION_LIFT_PERCENTAGE_ATTRIBUTE_ID, + "CurrentPositionLiftPercentage", (uint8_t *) &entry.currentPositionLiftPercentageValue, + ZCL_INT8U_ATTRIBUTE_TYPE); + } + if (entry.hasCurrentPositionTiltPercentageValue) + { + writeServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID, ZCL_WC_CURRENT_POSITION_TILT_PERCENTAGE_ATTRIBUTE_ID, + "CurrentPositionTiltPercentage", (uint8_t *) &entry.currentPositionTiltPercentageValue, + ZCL_INT8U_ATTRIBUTE_TYPE); } + if (entry.hasTargetPositionLiftPercent100thsValue) + { + writeServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID, + ZCL_WC_TARGET_POSITION_LIFT_PERCENT100_THS_ATTRIBUTE_ID, "TargetPositionLiftPercent100ths", + (uint8_t *) &entry.targetPositionLiftPercent100thsValue, ZCL_INT16U_ATTRIBUTE_TYPE); + } + if (entry.hasTargetPositionTiltPercent100thsValue) + { + writeServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID, + ZCL_WC_TARGET_POSITION_TILT_PERCENT100_THS_ATTRIBUTE_ID, "TargetPositionTiltPercent100ths", + (uint8_t *) &entry.targetPositionTiltPercent100thsValue, ZCL_INT16U_ATTRIBUTE_TYPE); + } +#endif + emberAfScenesMakeValid(endpoint, sceneId, groupId); + return EMBER_ZCL_STATUS_SUCCESS; } } @@ -785,7 +781,7 @@ bool emberAfPluginScenesServerParseAddScene( index = i; break; } - else if (index == EMBER_AF_SCENE_TABLE_NULL_INDEX && entry.endpoint == EMBER_AF_SCENE_TABLE_UNUSED_ENDPOINT_ID) + if (index == EMBER_AF_SCENE_TABLE_NULL_INDEX && entry.endpoint == EMBER_AF_SCENE_TABLE_UNUSED_ENDPOINT_ID) { index = i; } diff --git a/src/app/clusters/test-cluster-server/test-cluster-server.cpp b/src/app/clusters/test-cluster-server/test-cluster-server.cpp index ebbc8be7e70468..bc6d400cb1ad45 100644 --- a/src/app/clusters/test-cluster-server/test-cluster-server.cpp +++ b/src/app/clusters/test-cluster-server/test-cluster-server.cpp @@ -267,17 +267,15 @@ CHIP_ERROR TestAttrAccess::WriteListInt8uAttribute(const ConcreteDataAttributePa return iter.GetStatus(); } - else if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) + if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) { VerifyOrReturnError(gListUint8DataLen < kAttributeListLength, CHIP_ERROR_INVALID_ARGUMENT); ReturnErrorOnFailure(aDecoder.Decode(gListUint8Data[gListUint8DataLen])); gListUint8DataLen++; return CHIP_NO_ERROR; } - else - { - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; - } + + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } CHIP_ERROR TestAttrAccess::ReadListOctetStringAttribute(AttributeValueEncoder & aEncoder) @@ -316,7 +314,7 @@ CHIP_ERROR TestAttrAccess::WriteListOctetStringAttribute(const ConcreteDataAttri return iter.GetStatus(); } - else if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) + if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) { ByteSpan entry; ReturnErrorOnFailure(aDecoder.Decode(entry)); @@ -328,10 +326,8 @@ CHIP_ERROR TestAttrAccess::WriteListOctetStringAttribute(const ConcreteDataAttri gListOctetStringDataLen++; return CHIP_NO_ERROR; } - else - { - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; - } + + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } CHIP_ERROR TestAttrAccess::ReadListLongOctetStringAttribute(AttributeValueEncoder & aEncoder) @@ -368,7 +364,7 @@ CHIP_ERROR TestAttrAccess::WriteListLongOctetStringAttribute(const ConcreteDataA return iter.GetStatus(); } - else if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) + if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) { ByteSpan entry; ReturnErrorOnFailure(aDecoder.Decode(entry)); @@ -378,10 +374,8 @@ CHIP_ERROR TestAttrAccess::WriteListLongOctetStringAttribute(const ConcreteDataA gListLongOctetStringLen++; return CHIP_NO_ERROR; } - else - { - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; - } + + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } CHIP_ERROR TestAttrAccess::ReadListStructOctetStringAttribute(AttributeValueEncoder & aEncoder) @@ -434,7 +428,7 @@ CHIP_ERROR TestAttrAccess::WriteListStructOctetStringAttribute(const ConcreteDat return CHIP_NO_ERROR; } - else if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) + if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) { chip::app::Clusters::TestCluster::Structs::TestListStructOctet::DecodableType entry; ReturnErrorOnFailure(aDecoder.Decode(entry)); @@ -451,10 +445,8 @@ CHIP_ERROR TestAttrAccess::WriteListStructOctetStringAttribute(const ConcreteDat gListOperationalCertLen++; return CHIP_NO_ERROR; } - else - { - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; - } + + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } CHIP_ERROR TestAttrAccess::ReadListNullablesAndOptionalsStructAttribute(AttributeValueEncoder & aEncoder) @@ -481,7 +473,7 @@ CHIP_ERROR TestAttrAccess::WriteListNullablesAndOptionalsStructAttribute(const C return CHIP_NO_ERROR; } - else if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) + if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) { // And we only support one entry in the list. VerifyOrReturnError(count == 0, CHIP_ERROR_INVALID_ARGUMENT); @@ -524,10 +516,8 @@ CHIP_ERROR TestAttrAccess::WriteListNullablesAndOptionalsStructAttribute(const C return CHIP_NO_ERROR; } - else - { - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; - } + + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } CHIP_ERROR TestAttrAccess::ReadStructAttribute(AttributeValueEncoder & aEncoder) @@ -664,7 +654,7 @@ CHIP_ERROR TestAttrAccess::WriteListFabricScopedAttribute(const ConcreteDataAttr gListFabricScopedAttributeLen = dstIndex; return iter.GetStatus(); } - else if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) + if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) { VerifyOrReturnError(gListFabricScopedAttributeLen < kAttributeListLength, CHIP_ERROR_INVALID_ARGUMENT); @@ -675,10 +665,8 @@ CHIP_ERROR TestAttrAccess::WriteListFabricScopedAttribute(const ConcreteDataAttr gListFabricScopedAttributeLen++; return CHIP_NO_ERROR; } - else - { - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; - } + + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } } // namespace diff --git a/src/app/clusters/thermostat-server/thermostat-server.cpp b/src/app/clusters/thermostat-server/thermostat-server.cpp index 71b613e0b5052f..b8c5cccbf314b2 100644 --- a/src/app/clusters/thermostat-server/thermostat-server.cpp +++ b/src/app/clusters/thermostat-server/thermostat-server.cpp @@ -195,10 +195,10 @@ MatterThermostatClusterServerPreAttributeChangedCallback(const app::ConcreteAttr requested = static_cast(chip::Encoding::LittleEndian::Get16(value)); if (!HeatSupported) return imcode::UnsupportedAttribute; - else if (requested < AbsMinHeatSetpointLimit || requested < MinHeatSetpointLimit || requested > AbsMaxHeatSetpointLimit || - requested > MaxHeatSetpointLimit) + if (requested < AbsMinHeatSetpointLimit || requested < MinHeatSetpointLimit || requested > AbsMaxHeatSetpointLimit || + requested > MaxHeatSetpointLimit) return imcode::InvalidValue; - else if (AutoSupported) + if (AutoSupported) { if (requested > OccupiedCoolingSetpoint - DeadBandTemp) return imcode::InvalidValue; @@ -210,10 +210,10 @@ MatterThermostatClusterServerPreAttributeChangedCallback(const app::ConcreteAttr requested = static_cast(chip::Encoding::LittleEndian::Get16(value)); if (!CoolSupported) return imcode::UnsupportedAttribute; - else if (requested < AbsMinCoolSetpointLimit || requested < MinCoolSetpointLimit || requested > AbsMaxCoolSetpointLimit || - requested > MaxCoolSetpointLimit) + if (requested < AbsMinCoolSetpointLimit || requested < MinCoolSetpointLimit || requested > AbsMaxCoolSetpointLimit || + requested > MaxCoolSetpointLimit) return imcode::InvalidValue; - else if (AutoSupported) + if (AutoSupported) { if (requested < OccupiedHeatingSetpoint + DeadBandTemp) return imcode::InvalidValue; @@ -225,10 +225,10 @@ MatterThermostatClusterServerPreAttributeChangedCallback(const app::ConcreteAttr requested = static_cast(chip::Encoding::LittleEndian::Get16(value)); if (!(HeatSupported && OccupancySupported)) return imcode::UnsupportedAttribute; - else if (requested < AbsMinHeatSetpointLimit || requested < MinHeatSetpointLimit || requested > AbsMaxHeatSetpointLimit || - requested > MaxHeatSetpointLimit) + if (requested < AbsMinHeatSetpointLimit || requested < MinHeatSetpointLimit || requested > AbsMaxHeatSetpointLimit || + requested > MaxHeatSetpointLimit) return imcode::InvalidValue; - else if (AutoSupported) + if (AutoSupported) { if (requested > UnoccupiedCoolingSetpoint - DeadBandTemp) return imcode::InvalidValue; @@ -239,10 +239,10 @@ MatterThermostatClusterServerPreAttributeChangedCallback(const app::ConcreteAttr requested = static_cast(chip::Encoding::LittleEndian::Get16(value)); if (!(CoolSupported && OccupancySupported)) return imcode::UnsupportedAttribute; - else if (requested < AbsMinCoolSetpointLimit || requested < MinCoolSetpointLimit || requested > AbsMaxCoolSetpointLimit || - requested > MaxCoolSetpointLimit) + if (requested < AbsMinCoolSetpointLimit || requested < MinCoolSetpointLimit || requested > AbsMaxCoolSetpointLimit || + requested > MaxCoolSetpointLimit) return imcode::InvalidValue; - else if (AutoSupported) + if (AutoSupported) { if (requested < UnoccupiedHeatingSetpoint + DeadBandTemp) return imcode::InvalidValue; @@ -254,9 +254,9 @@ MatterThermostatClusterServerPreAttributeChangedCallback(const app::ConcreteAttr requested = static_cast(chip::Encoding::LittleEndian::Get16(value)); if (!HeatSupported) return imcode::UnsupportedAttribute; - else if (requested < AbsMinHeatSetpointLimit || requested > MaxHeatSetpointLimit || requested > AbsMaxHeatSetpointLimit) + if (requested < AbsMinHeatSetpointLimit || requested > MaxHeatSetpointLimit || requested > AbsMaxHeatSetpointLimit) return imcode::InvalidValue; - else if (AutoSupported) + if (AutoSupported) { if (requested > MinCoolSetpointLimit - DeadBandTemp) return imcode::InvalidValue; @@ -267,9 +267,9 @@ MatterThermostatClusterServerPreAttributeChangedCallback(const app::ConcreteAttr requested = static_cast(chip::Encoding::LittleEndian::Get16(value)); if (!HeatSupported) return imcode::UnsupportedAttribute; - else if (requested < AbsMinHeatSetpointLimit || requested < MinHeatSetpointLimit || requested > AbsMaxHeatSetpointLimit) + if (requested < AbsMinHeatSetpointLimit || requested < MinHeatSetpointLimit || requested > AbsMaxHeatSetpointLimit) return imcode::InvalidValue; - else if (AutoSupported) + if (AutoSupported) { if (requested > MaxCoolSetpointLimit - DeadBandTemp) return imcode::InvalidValue; @@ -280,9 +280,9 @@ MatterThermostatClusterServerPreAttributeChangedCallback(const app::ConcreteAttr requested = static_cast(chip::Encoding::LittleEndian::Get16(value)); if (!CoolSupported) return imcode::UnsupportedAttribute; - else if (requested < AbsMinCoolSetpointLimit || requested > MaxCoolSetpointLimit || requested > AbsMaxCoolSetpointLimit) + if (requested < AbsMinCoolSetpointLimit || requested > MaxCoolSetpointLimit || requested > AbsMaxCoolSetpointLimit) return imcode::InvalidValue; - else if (AutoSupported) + if (AutoSupported) { if (requested < MinHeatSetpointLimit + DeadBandTemp) return imcode::InvalidValue; @@ -293,9 +293,9 @@ MatterThermostatClusterServerPreAttributeChangedCallback(const app::ConcreteAttr requested = static_cast(chip::Encoding::LittleEndian::Get16(value)); if (!CoolSupported) return imcode::UnsupportedAttribute; - else if (requested < AbsMinCoolSetpointLimit || requested < MinCoolSetpointLimit || requested > AbsMaxCoolSetpointLimit) + if (requested < AbsMinCoolSetpointLimit || requested < MinCoolSetpointLimit || requested > AbsMaxCoolSetpointLimit) return imcode::InvalidValue; - else if (AutoSupported) + if (AutoSupported) { if (requested < MaxHeatSetpointLimit + DeadBandTemp) return imcode::InvalidValue; @@ -306,7 +306,7 @@ MatterThermostatClusterServerPreAttributeChangedCallback(const app::ConcreteAttr requested = *value; if (!AutoSupported) return imcode::UnsupportedAttribute; - else if (requested < 0 || requested > 25) + if (requested < 0 || requested > 25) return imcode::InvalidValue; return imcode::Success; } @@ -332,27 +332,25 @@ MatterThermostatClusterServerPreAttributeChangedCallback(const app::ConcreteAttr { return imcode::InvalidValue; } - else + + switch (ControlSequenceOfOperation) { - switch (ControlSequenceOfOperation) - { - case ThermostatControlSequence::kCoolingOnly: - case ThermostatControlSequence::kCoolingWithReheat: - if (RequestedSystemMode == ThermostatSystemMode::kHeat || - RequestedSystemMode == ThermostatSystemMode::kEmergencyHeating) - return imcode::InvalidValue; - else - return imcode::Success; + case ThermostatControlSequence::kCoolingOnly: + case ThermostatControlSequence::kCoolingWithReheat: + if (RequestedSystemMode == ThermostatSystemMode::kHeat || + RequestedSystemMode == ThermostatSystemMode::kEmergencyHeating) + return imcode::InvalidValue; + else + return imcode::Success; - case ThermostatControlSequence::kHeatingOnly: - case ThermostatControlSequence::kHeatingWithReheat: - if (RequestedSystemMode == ThermostatSystemMode::kCool || RequestedSystemMode == ThermostatSystemMode::kPrecooling) - return imcode::InvalidValue; - else - return imcode::Success; - default: + case ThermostatControlSequence::kHeatingOnly: + case ThermostatControlSequence::kHeatingWithReheat: + if (RequestedSystemMode == ThermostatSystemMode::kCool || RequestedSystemMode == ThermostatSystemMode::kPrecooling) + return imcode::InvalidValue; + else return imcode::Success; - } + default: + return imcode::Success; } } default: diff --git a/src/app/clusters/user-label-server/user-label-server.cpp b/src/app/clusters/user-label-server/user-label-server.cpp index 4ec09a32f4be23..bb5b2a54228344 100644 --- a/src/app/clusters/user-label-server/user-label-server.cpp +++ b/src/app/clusters/user-label-server/user-label-server.cpp @@ -117,16 +117,14 @@ CHIP_ERROR UserLabelAttrAccess::WriteLabelList(const ConcreteDataAttributePath & return provider->SetUserLabelList(endpoint, labelList); } - else if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) + if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem) { Structs::LabelStruct::DecodableType entry; ReturnErrorOnFailure(aDecoder.Decode(entry)); return provider->AppendUserLabel(endpoint, entry); } - else - { - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; - } + + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } CHIP_ERROR UserLabelAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index 671e367f640d48..f263284746240a 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -265,10 +265,8 @@ bool IsClusterDataVersionEqual(const ConcreteClusterPath & aConcreteClusterPath, { return true; } - else - { - return false; - } + + return false; } bool IsDeviceTypeOnEndpoint(DeviceTypeId deviceType, EndpointId endpoint) diff --git a/src/app/tests/integration/MockEvents.cpp b/src/app/tests/integration/MockEvents.cpp index 15852e3272300d..2efec7f805673a 100644 --- a/src/app/tests/integration/MockEvents.cpp +++ b/src/app/tests/integration/MockEvents.cpp @@ -201,8 +201,6 @@ bool MockEventGeneratorImpl::IsEventGeneratorStopped() gEventIsStopped = false; return true; } - else - { - return false; - } + + return false; } diff --git a/src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp b/src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp index c4e4b6448f44d9..a16fd1ad2d596c 100644 --- a/src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp +++ b/src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp @@ -58,26 +58,24 @@ chip::app::StatusIB ConvertToStatusIB(CHIP_ERROR err) { return StatusIB(Status::Failure, to_underlying(OperationalCertStatus::kInvalidPublicKey)); } - else if (CHIP_ERROR_WRONG_NODE_ID == err) + if (CHIP_ERROR_WRONG_NODE_ID == err) { return StatusIB(Status::Failure, to_underlying(OperationalCertStatus::kInvalidNodeOpId)); } - else if (CHIP_ERROR_UNSUPPORTED_CERT_FORMAT == err) + if (CHIP_ERROR_UNSUPPORTED_CERT_FORMAT == err) { return StatusIB(Status::Failure, to_underlying(OperationalCertStatus::kInvalidNOC)); } - else if (CHIP_ERROR_FABRIC_EXISTS == err) + if (CHIP_ERROR_FABRIC_EXISTS == err) { return StatusIB(Status::Failure, to_underlying(OperationalCertStatus::kFabricConflict)); } - else if (CHIP_ERROR_INVALID_FABRIC_ID == err) + if (CHIP_ERROR_INVALID_FABRIC_ID == err) { return StatusIB(Status::Failure, to_underlying(OperationalCertStatus::kInvalidFabricIndex)); } - else - { - return StatusIB(err); - } + + return StatusIB(err); } void CommissionerCommands::OnStatusUpdate(DevicePairingDelegate::Status status) diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index 84c0815fa7def2..afb69235dd49b5 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -627,10 +627,8 @@ EmberAfStatus emAfReadOrWriteAttribute(EmberAfAttributeSearchRecord * attRecord, { return typeSensitiveMemCopy(attRecord->clusterId, dst, src, am, write, readLength); } - else - { - return EMBER_ZCL_STATUS_FAILURE; - } + + return EMBER_ZCL_STATUS_FAILURE; } } else diff --git a/src/app/util/util.cpp b/src/app/util/util.cpp index 05fcf0975d6184..0df3624e14c763 100644 --- a/src/app/util/util.cpp +++ b/src/app/util/util.cpp @@ -554,38 +554,30 @@ int8_t emberAfCompareValues(const uint8_t * val1, const uint8_t * val2, uint16_t { return -1; } - else - { - return 0; - } - } - else - { // not supported + return 0; } + + // not supported + return 0; } - else - { // regular unsigned number comparison - for (i = 0; i < len; i++) - { - j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i])); - k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]); - if (j > k) - { - return 1; - } - if (k > j) - { - return -1; - } - else - { - // MISRA requires ..else if.. to have terminating else. - } + // regular unsigned number comparison + for (i = 0; i < len; i++) + { + j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i])); + k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]); + + if (j > k) + { + return 1; + } + if (k > j) + { + return -1; } - return 0; } + return 0; } #if 0 diff --git a/src/controller/AutoCommissioner.cpp b/src/controller/AutoCommissioner.cpp index 5629750df31624..b4a0ce68215e0f 100644 --- a/src/controller/AutoCommissioner.cpp +++ b/src/controller/AutoCommissioner.cpp @@ -169,18 +169,16 @@ CommissioningStage AutoCommissioner::GetNextCommissioningStageInternal(Commissio { return CommissioningStage::kThreadNetworkSetup; } - else - { - ChipLogError(Controller, "Required network information not provided in commissioning parameters"); - ChipLogError(Controller, "Parameters supplied: wifi (%s) thread (%s)", - mParams.GetWiFiCredentials().HasValue() ? "yes" : "no", - mParams.GetThreadOperationalDataset().HasValue() ? "yes" : "no"); - ChipLogError(Controller, "Device supports: wifi (%s) thread(%s)", - mDeviceCommissioningInfo.network.wifi.endpoint == kInvalidEndpointId ? "no" : "yes", - mDeviceCommissioningInfo.network.thread.endpoint == kInvalidEndpointId ? "no" : "yes"); - lastErr = CHIP_ERROR_INVALID_ARGUMENT; - return CommissioningStage::kCleanup; - } + + ChipLogError(Controller, "Required network information not provided in commissioning parameters"); + ChipLogError(Controller, "Parameters supplied: wifi (%s) thread (%s)", + mParams.GetWiFiCredentials().HasValue() ? "yes" : "no", + mParams.GetThreadOperationalDataset().HasValue() ? "yes" : "no"); + ChipLogError(Controller, "Device supports: wifi (%s) thread(%s)", + mDeviceCommissioningInfo.network.wifi.endpoint == kInvalidEndpointId ? "no" : "yes", + mDeviceCommissioningInfo.network.thread.endpoint == kInvalidEndpointId ? "no" : "yes"); + lastErr = CHIP_ERROR_INVALID_ARGUMENT; + return CommissioningStage::kCleanup; } else { diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 0818741b11c7af..b5115052ee2346 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -671,18 +671,16 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re } return CHIP_NO_ERROR; } - else if (current->IsSessionSetupInProgress()) + if (current->IsSessionSetupInProgress()) { - // We're not connected yet, but we're in the process of connecting. Pairing delegate will get a callback when connection - // completes + // We're not connected yet, but we're in the process of connecting. Pairing delegate will get a callback when + // connection completes return CHIP_NO_ERROR; } - else - { - // Something has gone strange. Delete the old device, try again. - ChipLogError(Controller, "Found unconnected device, removing"); - ReleaseCommissioneeDevice(current); - } + + // Something has gone strange. Delete the old device, try again. + ChipLogError(Controller, "Found unconnected device, removing"); + ReleaseCommissioneeDevice(current); } device = mCommissioneeDevicePool.CreateObject(); diff --git a/src/controller/python/ChipDeviceController-StorageDelegate.cpp b/src/controller/python/ChipDeviceController-StorageDelegate.cpp index 2e255e13e074b4..49fb532b24f177 100644 --- a/src/controller/python/ChipDeviceController-StorageDelegate.cpp +++ b/src/controller/python/ChipDeviceController-StorageDelegate.cpp @@ -96,18 +96,16 @@ CHIP_ERROR StorageAdapter::SyncGetKeyValue(const char * key, void * value, uint1 ChipLogDetail(Controller, "Key Not Found\n"); return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; } - else if (size < tmpSize) + if (size < tmpSize) { ChipLogDetail(Controller, "Buf not big enough\n"); size = tmpSize; return CHIP_ERROR_BUFFER_TOO_SMALL; } - else - { - ChipLogDetail(Controller, "Key Found %d\n", tmpSize); - size = tmpSize; - return CHIP_NO_ERROR; - } + + ChipLogDetail(Controller, "Key Found %d\n", tmpSize); + size = tmpSize; + return CHIP_NO_ERROR; } CHIP_ERROR StorageAdapter::SyncSetKeyValue(const char * key, const void * value, uint16_t size) diff --git a/src/controller/tests/TestWriteChunking.cpp b/src/controller/tests/TestWriteChunking.cpp index 9a6d756aea51ec..fa12d3415ba54b 100644 --- a/src/controller/tests/TestWriteChunking.cpp +++ b/src/controller/tests/TestWriteChunking.cpp @@ -165,17 +165,15 @@ CHIP_ERROR TestAttrAccess::Write(const app::ConcreteDataAttributePath & aPath, a ChipLogError(Zcl, "Decode result: %s", err.AsString()); return err; } - else if (aPath.mListOp == app::ConcreteDataAttributePath::ListOperation::AppendItem) + if (aPath.mListOp == app::ConcreteDataAttributePath::ListOperation::AppendItem) { ByteSpan listItem; CHIP_ERROR err = aDecoder.Decode(listItem); ChipLogError(Zcl, "Decode result: %s", err.AsString()); return err; } - else - { - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; - } + + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } /* diff --git a/src/controller/tests/data_model/TestRead.cpp b/src/controller/tests/data_model/TestRead.cpp index 0eef610e9fe89e..8e0d5b9b6b22b7 100644 --- a/src/controller/tests/data_model/TestRead.cpp +++ b/src/controller/tests/data_model/TestRead.cpp @@ -78,8 +78,8 @@ CHIP_ERROR ReadSingleClusterData(const Access::SubjectDescriptor & aSubjectDescr return CHIP_NO_ERROR; }); } - else if (aPath.mClusterId == app::Clusters::TestCluster::Id && - aPath.mAttributeId == app::Clusters::TestCluster::Attributes::Int16u::Id) + if (aPath.mClusterId == app::Clusters::TestCluster::Id && + aPath.mAttributeId == app::Clusters::TestCluster::Attributes::Int16u::Id) { AttributeValueEncoder::AttributeEncodeState state = (apEncoderState == nullptr ? AttributeValueEncoder::AttributeEncodeState() : *apEncoderState); @@ -88,57 +88,49 @@ CHIP_ERROR ReadSingleClusterData(const Access::SubjectDescriptor & aSubjectDescr return valueEncoder.Encode(++totalReadCount); } - else - { - AttributeReportIB::Builder & attributeReport = aAttributeReports.CreateAttributeReport(); - ReturnErrorOnFailure(aAttributeReports.GetError()); - AttributeDataIB::Builder & attributeData = attributeReport.CreateAttributeData(); - ReturnErrorOnFailure(attributeReport.GetError()); - TestCluster::Attributes::ListStructOctetString::TypeInfo::Type value; - TestCluster::Structs::TestListStructOctet::Type valueBuf[4]; - - value = valueBuf; - - uint8_t i = 0; - for (auto & item : valueBuf) - { - item.fabricIndex = i; - i++; - } - - attributeData.DataVersion(kDataVersion); - ReturnErrorOnFailure(attributeData.GetError()); - AttributePathIB::Builder & attributePath = attributeData.CreatePath(); - attributePath.Endpoint(aPath.mEndpointId) - .Cluster(aPath.mClusterId) - .Attribute(aPath.mAttributeId) - .EndOfAttributePathIB(); - ReturnErrorOnFailure(attributePath.GetError()); - - ReturnErrorOnFailure(DataModel::Encode(*(attributeData.GetWriter()), - TLV::ContextTag(to_underlying(AttributeDataIB::Tag::kData)), value)); - ReturnErrorOnFailure(attributeData.EndOfAttributeDataIB().GetError()); - return attributeReport.EndOfAttributeReportIB().GetError(); - } - } - else - { + AttributeReportIB::Builder & attributeReport = aAttributeReports.CreateAttributeReport(); ReturnErrorOnFailure(aAttributeReports.GetError()); - AttributeStatusIB::Builder & attributeStatus = attributeReport.CreateAttributeStatus(); - AttributePathIB::Builder & attributePath = attributeStatus.CreatePath(); + AttributeDataIB::Builder & attributeData = attributeReport.CreateAttributeData(); + ReturnErrorOnFailure(attributeReport.GetError()); + TestCluster::Attributes::ListStructOctetString::TypeInfo::Type value; + TestCluster::Structs::TestListStructOctet::Type valueBuf[4]; + + value = valueBuf; + + uint8_t i = 0; + for (auto & item : valueBuf) + { + item.fabricIndex = i; + i++; + } + + attributeData.DataVersion(kDataVersion); + ReturnErrorOnFailure(attributeData.GetError()); + AttributePathIB::Builder & attributePath = attributeData.CreatePath(); attributePath.Endpoint(aPath.mEndpointId).Cluster(aPath.mClusterId).Attribute(aPath.mAttributeId).EndOfAttributePathIB(); ReturnErrorOnFailure(attributePath.GetError()); - StatusIB::Builder & errorStatus = attributeStatus.CreateErrorStatus(); - ReturnErrorOnFailure(attributeStatus.GetError()); - errorStatus.EncodeStatusIB(StatusIB(Protocols::InteractionModel::Status::Busy)); - attributeStatus.EndOfAttributeStatusIB(); - ReturnErrorOnFailure(attributeStatus.GetError()); + ReturnErrorOnFailure( + DataModel::Encode(*(attributeData.GetWriter()), TLV::ContextTag(to_underlying(AttributeDataIB::Tag::kData)), value)); + ReturnErrorOnFailure(attributeData.EndOfAttributeDataIB().GetError()); return attributeReport.EndOfAttributeReportIB().GetError(); } - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; + AttributeReportIB::Builder & attributeReport = aAttributeReports.CreateAttributeReport(); + ReturnErrorOnFailure(aAttributeReports.GetError()); + AttributeStatusIB::Builder & attributeStatus = attributeReport.CreateAttributeStatus(); + AttributePathIB::Builder & attributePath = attributeStatus.CreatePath(); + attributePath.Endpoint(aPath.mEndpointId).Cluster(aPath.mClusterId).Attribute(aPath.mAttributeId).EndOfAttributePathIB(); + ReturnErrorOnFailure(attributePath.GetError()); + + StatusIB::Builder & errorStatus = attributeStatus.CreateErrorStatus(); + ReturnErrorOnFailure(attributeStatus.GetError()); + errorStatus.EncodeStatusIB(StatusIB(Protocols::InteractionModel::Status::Busy)); + attributeStatus.EndOfAttributeStatusIB(); + ReturnErrorOnFailure(attributeStatus.GetError()); + + return attributeReport.EndOfAttributeReportIB().GetError(); } bool IsClusterDataVersionEqual(const ConcreteClusterPath & aConcreteClusterPath, DataVersion aRequiredDataVersion) @@ -147,10 +139,8 @@ bool IsClusterDataVersionEqual(const ConcreteClusterPath & aConcreteClusterPath, { return true; } - else - { - return false; - } + + return false; } bool IsDeviceTypeOnEndpoint(DeviceTypeId deviceType, EndpointId endpoint) diff --git a/src/controller/tests/data_model/TestWrite.cpp b/src/controller/tests/data_model/TestWrite.cpp index 7df7d98ca5b218..8a873f09d63c92 100644 --- a/src/controller/tests/data_model/TestWrite.cpp +++ b/src/controller/tests/data_model/TestWrite.cpp @@ -116,7 +116,7 @@ CHIP_ERROR WriteSingleClusterData(const Access::SubjectDescriptor & aSubjectDesc return CHIP_NO_ERROR; } - else if (aPath.mClusterId == TestCluster::Id && aPath.mAttributeId == Attributes::ListFabricScoped::Id) + if (aPath.mClusterId == TestCluster::Id && aPath.mAttributeId == Attributes::ListFabricScoped::Id) { // Mock a invalid SubjectDescriptor AttributeValueDecoder decoder(aReader, Access::SubjectDescriptor()); diff --git a/src/darwin/Framework/CHIP/CHIPSetupPayload.mm b/src/darwin/Framework/CHIP/CHIPSetupPayload.mm index 12ed1485ff4cbd..ae229d6c2730bd 100644 --- a/src/darwin/Framework/CHIP/CHIPSetupPayload.mm +++ b/src/darwin/Framework/CHIP/CHIPSetupPayload.mm @@ -31,26 +31,28 @@ - (CHIPRendezvousInformationFlags)convertRendezvousFlags:(chip::RendezvousInform { if (value.Has(chip::RendezvousInformationFlag::kBLE)) { return kRendezvousInformationBLE; - } else if (value.Has(chip::RendezvousInformationFlag::kSoftAP)) { + } + if (value.Has(chip::RendezvousInformationFlag::kSoftAP)) { return kRendezvousInformationSoftAP; - } else if (value.Has(chip::RendezvousInformationFlag::kOnNetwork)) { + } + if (value.Has(chip::RendezvousInformationFlag::kOnNetwork)) { return kRendezvousInformationOnNetwork; - } else { - return kRendezvousInformationNone; } + return kRendezvousInformationNone; } - (CHIPCommissioningFlow)convertCommissioningFlow:(chip::CommissioningFlow)value { if (value == chip::CommissioningFlow::kStandard) { return kCommissioningFlowStandard; - } else if (value == chip::CommissioningFlow::kUserActionRequired) { + } + if (value == chip::CommissioningFlow::kUserActionRequired) { return kCommissioningFlowUserActionRequired; - } else if (value == chip::CommissioningFlow::kCustom) { + } + if (value == chip::CommissioningFlow::kCustom) { return kCommissioningFlowCustom; - } else { - return kCommissioningFlowInvalid; } + return kCommissioningFlowInvalid; } - (id)initWithSetupPayload:(chip::SetupPayload)setupPayload diff --git a/src/include/platform/KvsPersistentStorageDelegate.h b/src/include/platform/KvsPersistentStorageDelegate.h index 0142e55745c4f3..42ca6f481e6b4c 100644 --- a/src/include/platform/KvsPersistentStorageDelegate.h +++ b/src/include/platform/KvsPersistentStorageDelegate.h @@ -60,11 +60,9 @@ class KvsPersistentStorageDelegate : public PersistentStorageDelegate { return CHIP_ERROR_INVALID_ARGUMENT; } - else - { - // When size is zero, let's give a non-nullptr to the KVS backend - buffer = &emptyPlaceholder; - } + + // When size is zero, let's give a non-nullptr to the KVS backend + buffer = &emptyPlaceholder; } size_t bytesRead = 0; diff --git a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp index 848b31b61b792b..a8bf85244ad239 100644 --- a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp +++ b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp @@ -144,11 +144,9 @@ System::Clock::Timeout NodeLookupHandle::NextEventTimeout(System::Clock::Timesta { return mRequest.GetMaxLookupTime() - elapsed; } - else - { - ChipLogError(Discovery, "Unexpected timeout: lookup should have been cleaned already."); - return System::Clock::Timeout::zero(); - } + + ChipLogError(Discovery, "Unexpected timeout: lookup should have been cleaned already."); + return System::Clock::Timeout::zero(); } NodeLookupAction NodeLookupHandle::NextAction(System::Clock::Timestamp now) diff --git a/src/lib/dnssd/Discovery_ImplPlatform.cpp b/src/lib/dnssd/Discovery_ImplPlatform.cpp index b54f1c1a5f1e05..e8eb283e5a368c 100644 --- a/src/lib/dnssd/Discovery_ImplPlatform.cpp +++ b/src/lib/dnssd/Discovery_ImplPlatform.cpp @@ -523,8 +523,7 @@ CHIP_ERROR DiscoveryImplPlatform::PublishService(const char * serviceType, TextE #define PUBLISH_RECORDS(Type) \ ReturnErrorOnFailure(PublishService(k##Type##ServiceName, textEntries, textEntrySize, subTypes, subTypeSize, params)); \ m##Type##NodeAdvertisingParams = params; \ - mIs##Type##NodePublishing = true; \ - return CHIP_NO_ERROR; + mIs##Type##NodePublishing = true; CHIP_ERROR DiscoveryImplPlatform::Advertise(const OperationalAdvertisingParameters & params) { @@ -537,6 +536,8 @@ CHIP_ERROR DiscoveryImplPlatform::Advertise(const OperationalAdvertisingParamete ADD_PTR_RECORD(CompressedFabricId); PUBLISH_RECORDS(Operational); + + return CHIP_NO_ERROR; } CHIP_ERROR DiscoveryImplPlatform::Advertise(const CommissionAdvertisingParameters & params) @@ -556,21 +557,21 @@ CHIP_ERROR DiscoveryImplPlatform::Advertise(const CommissionAdvertisingParameter if (params.GetCommissionAdvertiseMode() == CommssionAdvertiseMode::kCommissioner) { PUBLISH_RECORDS(Commissioner); + return CHIP_NO_ERROR; } - else - { - ADD_TXT_RECORD(LongDiscriminator); - ADD_TXT_RECORD(CommissioningMode); - ADD_TXT_RECORD(RotatingDeviceId); - ADD_TXT_RECORD(PairingHint); - ADD_TXT_RECORD(PairingInstruction); - ADD_PTR_RECORD(ShortDiscriminator); - ADD_PTR_RECORD(LongDiscriminator); - ADD_PTR_RECORD(CommissioningMode); + ADD_TXT_RECORD(LongDiscriminator); + ADD_TXT_RECORD(CommissioningMode); + ADD_TXT_RECORD(RotatingDeviceId); + ADD_TXT_RECORD(PairingHint); + ADD_TXT_RECORD(PairingInstruction); - PUBLISH_RECORDS(Commissionable); - } + ADD_PTR_RECORD(ShortDiscriminator); + ADD_PTR_RECORD(LongDiscriminator); + ADD_PTR_RECORD(CommissioningMode); + + PUBLISH_RECORDS(Commissionable); + return CHIP_NO_ERROR; } CHIP_ERROR DiscoveryImplPlatform::RemoveServices() diff --git a/src/lib/shell/commands/BLE.cpp b/src/lib/shell/commands/BLE.cpp index 9563e4c83054bb..f12c2101561b6d 100644 --- a/src/lib/shell/commands/BLE.cpp +++ b/src/lib/shell/commands/BLE.cpp @@ -67,10 +67,8 @@ CHIP_ERROR BLEAdvertiseHandler(int argc, char ** argv) streamer_printf(sout, "Stopping BLE advertising\r\n"); return ConnectivityMgr().SetBLEAdvertisingEnabled(false); } - else - { - streamer_printf(sout, "BLE advertising already stopped\r\n"); - } + + streamer_printf(sout, "BLE advertising already stopped\r\n"); } else if (strcmp(argv[0], "state") == 0) { diff --git a/src/lib/shell/commands/Config.cpp b/src/lib/shell/commands/Config.cpp index 10486fc2f17fc8..580a3451f6c154 100644 --- a/src/lib/shell/commands/Config.cpp +++ b/src/lib/shell/commands/Config.cpp @@ -157,10 +157,8 @@ static CHIP_ERROR ConfigDiscriminator(int argc, char ** argv) { return ConfigGetSetupDiscriminator(false); } - else - { - return ConfigSetSetupDiscriminator(argv[0]); - } + + return ConfigSetSetupDiscriminator(argv[0]); } static CHIP_ERROR PrintAllConfigs() diff --git a/src/lib/shell/commands/OnboardingCodes.cpp b/src/lib/shell/commands/OnboardingCodes.cpp index 49e388cf9ab0a1..3acb3a4e6501f7 100644 --- a/src/lib/shell/commands/OnboardingCodes.cpp +++ b/src/lib/shell/commands/OnboardingCodes.cpp @@ -104,17 +104,17 @@ static CHIP_ERROR RendezvousStringToFlag(char * str, chip::RendezvousInformation *aRendezvousFlags = chip::RendezvousInformationFlag::kNone; return CHIP_NO_ERROR; } - else if (strcmp(str, "softap") == 0) + if (strcmp(str, "softap") == 0) { *aRendezvousFlags = chip::RendezvousInformationFlag::kSoftAP; return CHIP_NO_ERROR; } - else if (strcmp(str, "ble") == 0) + if (strcmp(str, "ble") == 0) { *aRendezvousFlags = chip::RendezvousInformationFlag::kBLE; return CHIP_NO_ERROR; } - else if (strcmp(str, "onnetwork") == 0) + if (strcmp(str, "onnetwork") == 0) { *aRendezvousFlags = chip::RendezvousInformationFlag::kOnNetwork; return CHIP_NO_ERROR; @@ -146,18 +146,16 @@ static CHIP_ERROR OnboardingHandler(int argc, char ** argv) { return GetOnboardingQRCode(false, aRendezvousFlags); } - else if (strcmp(argv[1], "qrcodeurl") == 0) + if (strcmp(argv[1], "qrcodeurl") == 0) { return GetOnboardingQRCodeUrl(false, aRendezvousFlags); } - else if (strcmp(argv[1], "manualpairingcode") == 0) + if (strcmp(argv[1], "manualpairingcode") == 0) { return GetOnboardingManualPairingCode(false, aRendezvousFlags); } - else - { - return CHIP_ERROR_INVALID_ARGUMENT; - } + + return CHIP_ERROR_INVALID_ARGUMENT; } void RegisterOnboardingCodesCommands() diff --git a/src/lib/shell/commands/WiFi.cpp b/src/lib/shell/commands/WiFi.cpp index ed531e6bf0bf20..c54cba75c221c2 100644 --- a/src/lib/shell/commands/WiFi.cpp +++ b/src/lib/shell/commands/WiFi.cpp @@ -102,7 +102,7 @@ static CHIP_ERROR WiFiModeHandler(int argc, char ** argv) { return PrintWiFiMode(); } - else if (argc != 1) + if (argc != 1) { return CHIP_ERROR_INVALID_ARGUMENT; } diff --git a/src/lib/support/TestPersistentStorageDelegate.h b/src/lib/support/TestPersistentStorageDelegate.h index 5466daa1acb4e5..56e34ba2ac9a8c 100644 --- a/src/lib/support/TestPersistentStorageDelegate.h +++ b/src/lib/support/TestPersistentStorageDelegate.h @@ -69,12 +69,10 @@ class TestPersistentStorageDelegate : public PersistentStorageDelegate size = CanCastTo(valueSize) ? static_cast(valueSize) : 0; return CHIP_ERROR_BUFFER_TOO_SMALL; } - else - { - size = static_cast(valueSize); - memcpy(buffer, value.data(), size); - return CHIP_NO_ERROR; - } + + size = static_cast(valueSize); + memcpy(buffer, value.data(), size); + return CHIP_NO_ERROR; } CHIP_ERROR SyncSetKeyValue(const char * key, const void * value, uint16_t size) override @@ -93,18 +91,14 @@ class TestPersistentStorageDelegate : public PersistentStorageDelegate mStorage[key] = std::vector(); return CHIP_NO_ERROR; } - else - { - return CHIP_ERROR_INVALID_ARGUMENT; - } + + return CHIP_ERROR_INVALID_ARGUMENT; } // Handle non-empty values - else - { - const uint8_t * bytes = static_cast(value); - mStorage[key] = std::vector(bytes, bytes + size); - return CHIP_NO_ERROR; - } + + const uint8_t * bytes = static_cast(value); + mStorage[key] = std::vector(bytes, bytes + size); + return CHIP_NO_ERROR; } CHIP_ERROR SyncDeleteKeyValue(const char * key) override diff --git a/src/lib/support/tests/TestStateMachine.cpp b/src/lib/support/tests/TestStateMachine.cpp index 47baef33737049..da29ce8dbae121 100644 --- a/src/lib/support/tests/TestStateMachine.cpp +++ b/src/lib/support/tests/TestStateMachine.cpp @@ -121,33 +121,31 @@ struct Transitions { return mFactory.CreateState2(); } - else if (state.Is() && event.Is()) + if (state.Is() && event.Is()) { return mFactory.CreateState1(); } - else if (state.Is() && event.Is()) + if (state.Is() && event.Is()) { // legal - Dispatches event without transition mCtx.Dispatch(Event::Create()); return {}; } - else if (state.Is() && event.Is()) + if (state.Is() && event.Is()) { - // mCtx.Dispatch(Event::Create()); // dsipatching an event and returning a transition would be illegal + // mCtx.Dispatch(Event::Create()); // dispatching an event and returning a transition would be illegal return mFactory.CreateState1(); } - else if (state.Is() && event.Is()) + if (state.Is() && event.Is()) { return mFactory.CreateState3(); } - else if (state.Is() && event.Is()) + if (state.Is() && event.Is()) { return mFactory.CreateState2(); } - else - { - return {}; - } + + return {}; } }; diff --git a/src/platform/Darwin/BleConnectionDelegateImpl.mm b/src/platform/Darwin/BleConnectionDelegateImpl.mm index 9f1038dc85c1bd..d2bff08e99a953 100644 --- a/src/platform/Darwin/BleConnectionDelegateImpl.mm +++ b/src/platform/Darwin/BleConnectionDelegateImpl.mm @@ -186,10 +186,8 @@ - (BOOL)checkDiscriminator:(uint16_t)discriminator constexpr uint16_t kManualSetupDiscriminatorFieldBitMask = maxManualDiscriminatorValue << manualSetupDiscriminatorOffsetInBits; if (_deviceDiscriminator == (_deviceDiscriminator & kManualSetupDiscriminatorFieldBitMask)) { return _deviceDiscriminator == (discriminator & kManualSetupDiscriminatorFieldBitMask); - } else { - // else compare the entire thing - return _deviceDiscriminator == discriminator; - } + } // else compare the entire thing + return _deviceDiscriminator == discriminator; } - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral diff --git a/src/platform/Darwin/DnssdImpl.cpp b/src/platform/Darwin/DnssdImpl.cpp index 5b4ea4de9ca1b3..073974f4dab0ee 100644 --- a/src/platform/Darwin/DnssdImpl.cpp +++ b/src/platform/Darwin/DnssdImpl.cpp @@ -501,24 +501,22 @@ static CHIP_ERROR GetAddrInfo(void * context, DnssdResolveCallback callback, uin return MdnsContexts::GetInstance().Add(sdCtx, sdRef); } - else - { - sockaddr_in6 sockaddr; - memset(&sockaddr, 0, sizeof(sockaddr)); - sockaddr.sin6_len = sizeof(sockaddr); - sockaddr.sin6_family = AF_INET6; - sockaddr.sin6_addr = in6addr_loopback; - sockaddr.sin6_port = htons((unsigned short) port); - uint32_t ttl = 120; // default TTL for records with hostnames is 120 seconds - uint32_t interface = 0; // Set interface to ANY (0) - network stack can decide how to route this. - OnGetAddrInfo(nullptr, 0 /* flags */, interface, kDNSServiceErr_NoError, hostname, - reinterpret_cast(&sockaddr), ttl, sdCtx); - - // Don't leak memory. - sdCtx->serviceRef = nullptr; - MdnsContexts::GetInstance().Delete(sdCtx); - return CHIP_NO_ERROR; - } + + sockaddr_in6 sockaddr; + memset(&sockaddr, 0, sizeof(sockaddr)); + sockaddr.sin6_len = sizeof(sockaddr); + sockaddr.sin6_family = AF_INET6; + sockaddr.sin6_addr = in6addr_loopback; + sockaddr.sin6_port = htons((unsigned short) port); + uint32_t ttl = 120; // default TTL for records with hostnames is 120 seconds + uint32_t interface = 0; // Set interface to ANY (0) - network stack can decide how to route this. + OnGetAddrInfo(nullptr, 0 /* flags */, interface, kDNSServiceErr_NoError, hostname, + reinterpret_cast(&sockaddr), ttl, sdCtx); + + // Don't leak memory. + sdCtx->serviceRef = nullptr; + MdnsContexts::GetInstance().Delete(sdCtx); + return CHIP_NO_ERROR; } static void OnResolve(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceId, DNSServiceErrorType err, diff --git a/src/platform/Darwin/UUIDHelperImpl.mm b/src/platform/Darwin/UUIDHelperImpl.mm index 807b143f46991a..3f5b3df0d7641b 100644 --- a/src/platform/Darwin/UUIDHelperImpl.mm +++ b/src/platform/Darwin/UUIDHelperImpl.mm @@ -35,13 +35,10 @@ + (CBUUID *)GetShortestServiceUUID:(const chip::Ble::ChipBleUUID *)svcId if ((0 == svcId->bytes[0]) && (0 == svcId->bytes[1])) { // the highest 2 bytes are both 0, so we just need 2 bytes return [CBUUID UUIDWithData:[NSData dataWithBytes:(svcId->bytes + 2) length:2]]; - } else { - // we need to use 4 bytes - return [CBUUID UUIDWithData:[NSData dataWithBytes:svcId->bytes length:4]]; - } - } else { - // it cannot be shortened as it doesn't match with the BLE Service UUID Base - return [CBUUID UUIDWithData:[NSData dataWithBytes:svcId->bytes length:16]]; + } // we need to use 4 bytes + return [CBUUID UUIDWithData:[NSData dataWithBytes:svcId->bytes length:4]]; } + // it cannot be shortened as it doesn't match with the BLE Service UUID Base + return [CBUUID UUIDWithData:[NSData dataWithBytes:svcId->bytes length:16]]; } @end diff --git a/src/platform/Linux/DeviceInfoProviderImpl.cpp b/src/platform/Linux/DeviceInfoProviderImpl.cpp index 323667512c666d..395da9eadf801a 100644 --- a/src/platform/Linux/DeviceInfoProviderImpl.cpp +++ b/src/platform/Linux/DeviceInfoProviderImpl.cpp @@ -110,10 +110,8 @@ bool DeviceInfoProviderImpl::FixedLabelIteratorImpl::Next(FixedLabelType & outpu return true; } - else - { - return false; - } + + return false; } CHIP_ERROR DeviceInfoProviderImpl::SetUserLabelLength(EndpointId endpoint, size_t val) @@ -272,10 +270,8 @@ bool DeviceInfoProviderImpl::SupportedLocalesIteratorImpl::Next(CharSpan & outpu return true; } - else - { - return false; - } + + return false; } DeviceInfoProvider::SupportedCalendarTypesIterator * DeviceInfoProviderImpl::IterateSupportedCalendarTypes() @@ -347,10 +343,8 @@ bool DeviceInfoProviderImpl::SupportedCalendarTypesIteratorImpl::Next(CalendarTy mIndex++; return true; } - else - { - return false; - } + + return false; } } // namespace DeviceLayer diff --git a/src/protocols/secure_channel/CASESession.cpp b/src/protocols/secure_channel/CASESession.cpp index 3e518b80ef232a..94d4553e7057fa 100644 --- a/src/protocols/secure_channel/CASESession.cpp +++ b/src/protocols/secure_channel/CASESession.cpp @@ -277,7 +277,7 @@ CHIP_ERROR CASESession::RecoverInitiatorIpk() ChipLogError(SecureChannel, "Failed to obtain IPK for initiating: %" CHIP_ERROR_FORMAT, err.Format()); return err; } - else if ((ipkKeySet.num_keys_used == 0) || (ipkKeySet.num_keys_used > Credentials::GroupDataProvider::KeySet::kEpochKeysMax)) + if ((ipkKeySet.num_keys_used == 0) || (ipkKeySet.num_keys_used > Credentials::GroupDataProvider::KeySet::kEpochKeysMax)) { ChipLogError(SecureChannel, "Found invalid IPK keyset for initiator."); return CHIP_ERROR_INTERNAL; diff --git a/src/tools/chip-cert/Cmd_GenAttCert.cpp b/src/tools/chip-cert/Cmd_GenAttCert.cpp index f2e62003bb1905..766f64b69c1fae 100644 --- a/src/tools/chip-cert/Cmd_GenAttCert.cpp +++ b/src/tools/chip-cert/Cmd_GenAttCert.cpp @@ -271,7 +271,7 @@ bool Cmd_GenAttCert(int argc, char * argv[]) fprintf(stderr, "Please specify attestation certificate type.\n"); return false; } - else if (gAttCertType == kAttCertType_DAC) + if (gAttCertType == kAttCertType_DAC) { if (gSubjectVID == VendorId::NotSpecified || gSubjectPID == 0) { @@ -301,7 +301,8 @@ bool Cmd_GenAttCert(int argc, char * argv[]) fprintf(stderr, "Please specify the CA certificate file name using the --ca-cert option.\n"); return false; } - else if (gCACertFileName != nullptr && gAttCertType == kAttCertType_PAA) + + if (gCACertFileName != nullptr && gAttCertType == kAttCertType_PAA) { fprintf(stderr, "Please don't specify --ca-cert option for the self signed certificate. \n"); return false; diff --git a/src/tools/spake2p/Cmd_GenVerifier.cpp b/src/tools/spake2p/Cmd_GenVerifier.cpp index bd583c242bd0ef..92bfe3808cf88e 100644 --- a/src/tools/spake2p/Cmd_GenVerifier.cpp +++ b/src/tools/spake2p/Cmd_GenVerifier.cpp @@ -231,12 +231,12 @@ bool Cmd_GenVerifier(int argc, char * argv[]) fprintf(stderr, "Please specify at least one of the 'salt' or 'salt-len' parameters.\n"); return false; } - else if (gSalt != nullptr && gSaltLen != 0 && gSaltLen != strlen(gSalt)) + if (gSalt != nullptr && gSaltLen != 0 && gSaltLen != strlen(gSalt)) { fprintf(stderr, "The specified 'salt-len' doesn't match the length of 'salt' parameter.\n"); return false; } - else if (gSaltLen == 0) + if (gSaltLen == 0) { gSaltLen = static_cast(strlen(gSalt)); } diff --git a/src/transport/SecureSessionTable.h b/src/transport/SecureSessionTable.h index d023ccb62fdbdb..7d9cfe794853d5 100644 --- a/src/transport/SecureSessionTable.h +++ b/src/transport/SecureSessionTable.h @@ -233,10 +233,8 @@ class SecureSessionTable uint16_t available = static_cast(candidate_base + offset); return MakeOptional(available); } - else - { - return NullOptional; - } + + return NullOptional; } BitMapObjectPool mEntries;