Skip to content

Commit

Permalink
Clang-tidy readability-else-after-return (project-chip#16312)
Browse files Browse the repository at this point in the history
* use clang-tidy to readability-else-after-return

* Restyle

* Ran a 2nd pass

* Restyle

* Ran a 2nd pass

* Restyle
  • Loading branch information
andy31415 authored Mar 16, 2022
1 parent 2091ce3 commit 0c43841
Show file tree
Hide file tree
Showing 55 changed files with 223 additions and 341 deletions.
2 changes: 1 addition & 1 deletion src/access/examples/ExampleAccessControlDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ class EntryDelegate : public Entry::Delegate
{
return CHIP_NO_ERROR;
}
else if (auto * storage = EntryStorage::Find(nullptr))
if (auto * storage = EntryStorage::Find(nullptr))
{
*storage = *mStorage;
mStorage = storage;
Expand Down
2 changes: 1 addition & 1 deletion src/app/AttributePathExpandIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ bool AttributePathExpandIterator::Next()
// Return true will skip the increment of mClusterIndex, mEndpointIndex and mpClusterInfo.
return true;
}
else if (mGlobalAttributeIndex < mGlobalAttributeEndIndex)
if (mGlobalAttributeIndex < mGlobalAttributeEndIndex)
{
// Return a path pointing to the next global attribute.
mOutputPath.mAttributeId = GlobalAttributesNotInMetadata[mGlobalAttributeIndex];
Expand Down
8 changes: 3 additions & 5 deletions src/app/ChunkedWriteCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ void ChunkedWriteCallback::OnResponse(const WriteClient * apWriteClient, const C
}
return;
}
else
{
// This is a response to another attribute write. Report the final result of last attribute write.
callback->OnResponse(apWriteClient, mLastAttributePath.Value(), mAttributeStatus);
}

// This is a response to another attribute write. Report the final result of last attribute write.
callback->OnResponse(apWriteClient, mLastAttributePath.Value(), mAttributeStatus);
}

// This is the first report for a new attribute. We assume it will never be a list item operation.
Expand Down
6 changes: 2 additions & 4 deletions src/app/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,8 @@ TLV::TLVWriter * CommandHandler::GetCommandDataIBTLVWriter()
{
return nullptr;
}
else
{
return mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().GetCommand().GetWriter();
}

return mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().GetCommand().GetWriter();
}

FabricIndex CommandHandler::GetAccessingFabricIndex() const
Expand Down
6 changes: 2 additions & 4 deletions src/app/CommandSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,8 @@ TLV::TLVWriter * CommandSender::GetCommandDataIBTLVWriter()
{
return nullptr;
}
else
{
return mInvokeRequestBuilder.GetInvokeRequests().GetCommandData().GetWriter();
}

return mInvokeRequestBuilder.GetInvokeRequests().GetCommandData().GetWriter();
}

CHIP_ERROR CommandSender::HandleTimedStatus(const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload)
Expand Down
12 changes: 5 additions & 7 deletions src/app/EventManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ CHIP_ERROR EventManagement::CopyAndAdjustDeltaTime(const TLVReader & aReader, si
// Does not go on the wire.
return CHIP_NO_ERROR;
}
else if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kSystemTimestamp))) && !(ctx->mpContext->mFirst))
if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kSystemTimestamp))) && !(ctx->mpContext->mFirst))
{
return ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp)),
ctx->mpContext->mCurrentTime.mValue - ctx->mpContext->mPreviousTime.mValue);
Expand Down Expand Up @@ -501,12 +501,10 @@ CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, c
{
break;
}
else
{
buffer = buffer->GetNextCircularEventBuffer();
assert(buffer != nullptr);
// code guarantees that every PriorityLevel has a buffer destination.
}

buffer = buffer->GetNextCircularEventBuffer();
assert(buffer != nullptr);
// code guarantees that every PriorityLevel has a buffer destination.
}

mBytesWritten += writer.GetLengthWritten();
Expand Down
11 changes: 5 additions & 6 deletions src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,12 +904,11 @@ bool ReadClient::ResubscribeIfNeeded()
ChipLogProgress(DataManagement, "Fail to resubscribe with error %" CHIP_ERROR_FORMAT, err.Format());
return false;
}
else
{
ChipLogProgress(DataManagement,
"Will try to Resubscribe to %02x:" ChipLogFormatX64 " at retry index %" PRIu32 " after %" PRIu32 "ms",
mFabricIndex, ChipLogValueX64(mPeerNodeId), mNumRetries, intervalMsec);
}

ChipLogProgress(DataManagement,
"Will try to Resubscribe to %02x:" ChipLogFormatX64 " at retry index %" PRIu32 " after %" PRIu32 "ms",
mFabricIndex, ChipLogValueX64(mPeerNodeId), mNumRetries, intervalMsec);

return true;
}

Expand Down
6 changes: 2 additions & 4 deletions src/app/WriteClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,8 @@ CHIP_ERROR WriteClient::PutPreencodedAttribute(const ConcreteDataAttributePath &
}
return err;
}
else // We are writing a non-list attribute, or we are writing a single element of a list.
{
return PutSinglePreencodedAttributeWritePayload(attributePath, data);
}
// We are writing a non-list attribute, or we are writing a single element of a list.
return PutSinglePreencodedAttributeWritePayload(attributePath, data);
}

const char * WriteClient::GetStateStr() const
Expand Down
6 changes: 2 additions & 4 deletions src/app/WriteClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,8 @@ class WriteClient : public Messaging::ExchangeDelegate
attributePath.mClusterId, attributePath.mAttributeId, aDataVersion),
value);
}
else
{
return EncodeAttribute(attributePath, value.Value());
}

return EncodeAttribute(attributePath, value.Value());
}

/**
Expand Down
12 changes: 4 additions & 8 deletions src/app/data-model/DecodableList.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ class DecodableList
{
return CHIP_NO_ERROR;
}
else
{
return mStatus;
}

return mStatus;
}

private:
Expand Down Expand Up @@ -194,10 +192,8 @@ class DecodableList
*size = 0;
return CHIP_NO_ERROR;
}
else
{
return mReader.CountRemainingInContainer(size);
}

return mReader.CountRemainingInContainer(size);
}

CHIP_ERROR Decode(TLV::TLVReader & reader)
Expand Down
7 changes: 3 additions & 4 deletions src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,9 @@ CHIP_ERROR Engine::ScheduleEventDelivery(ConcreteEventPath & aPath, uint32_t aBy
ChipLogDetail(DataManagement, "urgent event schedule run");
return ScheduleRun();
}
else
{
return ScheduleBufferPressureEventDelivery(aBytesWritten);
}

return ScheduleBufferPressureEventDelivery(aBytesWritten);

return CHIP_NO_ERROR;
}

Expand Down
8 changes: 3 additions & 5 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,9 @@ class Server
{
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;
Expand Down
30 changes: 13 additions & 17 deletions src/app/tests/suites/pics/PICSBooleanExpressionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,15 @@ bool PICSBooleanExpressionParser::EvaluateExpression(std::vector<std::string> &
bool rightExpr = EvaluateExpression(tokens, PICS, index);
return leftExpr && rightExpr;
}
else if (token == "||")
if (token == "||")
{
index++;
bool rightExpr = EvaluateExpression(tokens, PICS, index);
return leftExpr || rightExpr;
}
else
{
ChipLogError(chipTool, "Unknown token: '%s'", token.c_str());
chipDie();
}

ChipLogError(chipTool, "Unknown token: '%s'", token.c_str());
chipDie();
}

bool PICSBooleanExpressionParser::EvaluateSubExpression(std::vector<std::string> & tokens, std::map<std::string, bool> & PICS,
Expand All @@ -145,23 +143,21 @@ bool PICSBooleanExpressionParser::EvaluateSubExpression(std::vector<std::string>
index++;
return expr;
}
else if (token == "!")
if (token == "!")
{
index++;
bool expr = EvaluateSubExpression(tokens, PICS, index);
return !expr;
}
else
{
index++;

if (PICS.find(token) == PICS.end())
{
// By default, let's consider that if a PICS item is not defined, it is |false|.
// It allows to create a file that only contains enabled features.
return false;
}
index++;

return PICS[token];
if (PICS.find(token) == PICS.end())
{
// By default, let's consider that if a PICS item is not defined, it is |false|.
// It allows to create a file that only contains enabled features.
return false;
}

return PICS[token];
}
12 changes: 4 additions & 8 deletions src/app/util/af-event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,8 @@ EmberStatus emberAfEventControlSetDelayQS(EmberEventControl * control, uint32_t
{
return emberEventControlSetDelayMS(control, delayQs << 8);
}
else
{
return EMBER_BAD_ARGUMENT;
}

return EMBER_BAD_ARGUMENT;
}

EmberStatus emberAfEventControlSetDelayMinutes(EmberEventControl * control, uint16_t delayM)
Expand All @@ -207,10 +205,8 @@ EmberStatus emberAfEventControlSetDelayMinutes(EmberEventControl * control, uint
{
return emberEventControlSetDelayMS(control, static_cast<uint32_t>(delayM) << 16);
}
else
{
return EMBER_BAD_ARGUMENT;
}

return EMBER_BAD_ARGUMENT;
}

EmberStatus emberAfScheduleTickExtended(EndpointId endpoint, ClusterId clusterId, bool isClient, uint32_t delayMs,
Expand Down
48 changes: 20 additions & 28 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,19 +370,17 @@ EmberAfStatus emAfClusterPreAttributeChangedCallback(const app::ConcreteAttribut
{
return EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE;
}
else

EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
// Casting and calling a function pointer on the same line results in ignoring the return
// of the call on gcc-arm-none-eabi-9-2019-q4-major
EmberAfClusterPreAttributeChangedCallback f = (EmberAfClusterPreAttributeChangedCallback)(
emberAfFindClusterFunction(cluster, CLUSTER_MASK_PRE_ATTRIBUTE_CHANGED_FUNCTION));
if (f != NULL)
{
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
// Casting and calling a function pointer on the same line results in ignoring the return
// of the call on gcc-arm-none-eabi-9-2019-q4-major
EmberAfClusterPreAttributeChangedCallback f = (EmberAfClusterPreAttributeChangedCallback)(
emberAfFindClusterFunction(cluster, CLUSTER_MASK_PRE_ATTRIBUTE_CHANGED_FUNCTION));
if (f != NULL)
{
status = f(attributePath, attributeType, size, value);
}
return status;
status = f(attributePath, attributeType, size, value);
}
return status;
}

static void initializeEndpoint(EmberAfDefinedEndpoint * definedEndpoint)
Expand Down Expand Up @@ -623,17 +621,15 @@ EmberAfStatus emAfReadOrWriteAttribute(EmberAfAttributeSearchRecord * attRecord,
: emberAfExternalAttributeReadCallback(attRecord->endpoint, attRecord->clusterId,
am, buffer, emberAfAttributeSize(am)));
}

// Internal storage is only supported for fixed endpoints
if (!isDynamicEndpoint)
{
return typeSensitiveMemCopy(attRecord->clusterId, dst, src, am, write, readLength);
}
else
{
// Internal storage is only supported for fixed endpoints
if (!isDynamicEndpoint)
{
return typeSensitiveMemCopy(attRecord->clusterId, dst, src, am, write, readLength);
}
else
{
return EMBER_ZCL_STATUS_FAILURE;
}
return EMBER_ZCL_STATUS_FAILURE;
}
}
}
Expand Down Expand Up @@ -750,10 +746,8 @@ bool emberAfContainsServerFromIndex(uint16_t index, ClusterId clusterId)
{
return false;
}
else
{
return emberAfFindClusterInType(emAfEndpoints[index].endpointType, clusterId, CLUSTER_MASK_SERVER);
}

return emberAfFindClusterInType(emAfEndpoints[index].endpointType, clusterId, CLUSTER_MASK_SERVER);
}

namespace chip {
Expand Down Expand Up @@ -797,10 +791,8 @@ const EmberAfCluster * emberAfFindCluster(EndpointId endpoint, ClusterId cluster
{
return NULL;
}
else
{
return emberAfFindClusterInType(emAfEndpoints[ep].endpointType, clusterId, mask);
}

return emberAfFindClusterInType(emAfEndpoints[ep].endpointType, clusterId, mask);
}

// Returns cluster within the endpoint; Does not ignore disabled endpoints
Expand Down
26 changes: 12 additions & 14 deletions src/app/util/binding-table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,21 @@ CHIP_ERROR BindingTable::Add(const EmberBindingTableEntry & entry)
mBindingTable[newIndex].type = EMBER_UNUSED_BINDING;
return error;
}

if (mTail == kNextNullIndex)
{
mTail = newIndex;
mHead = newIndex;
}
else
{
if (mTail == kNextNullIndex)
{
mTail = newIndex;
mHead = newIndex;
}
else
{
mNextIndex[mTail] = newIndex;
mNextIndex[newIndex] = kNextNullIndex;
mTail = newIndex;
}

mSize++;
return CHIP_NO_ERROR;
mNextIndex[mTail] = newIndex;
mNextIndex[newIndex] = kNextNullIndex;
mTail = newIndex;
}

mSize++;
return CHIP_NO_ERROR;
}

const EmberBindingTableEntry & BindingTable::GetAt(uint8_t index)
Expand Down
Loading

0 comments on commit 0c43841

Please sign in to comment.