Skip to content

Commit 0c43841

Browse files
authored
Clang-tidy readability-else-after-return (project-chip#16312)
* use clang-tidy to readability-else-after-return * Restyle * Ran a 2nd pass * Restyle * Ran a 2nd pass * Restyle
1 parent 2091ce3 commit 0c43841

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+223
-341
lines changed

src/access/examples/ExampleAccessControlDelegate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ class EntryDelegate : public Entry::Delegate
870870
{
871871
return CHIP_NO_ERROR;
872872
}
873-
else if (auto * storage = EntryStorage::Find(nullptr))
873+
if (auto * storage = EntryStorage::Find(nullptr))
874874
{
875875
*storage = *mStorage;
876876
mStorage = storage;

src/app/AttributePathExpandIterator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ bool AttributePathExpandIterator::Next()
205205
// Return true will skip the increment of mClusterIndex, mEndpointIndex and mpClusterInfo.
206206
return true;
207207
}
208-
else if (mGlobalAttributeIndex < mGlobalAttributeEndIndex)
208+
if (mGlobalAttributeIndex < mGlobalAttributeEndIndex)
209209
{
210210
// Return a path pointing to the next global attribute.
211211
mOutputPath.mAttributeId = GlobalAttributesNotInMetadata[mGlobalAttributeIndex];

src/app/ChunkedWriteCallback.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ void ChunkedWriteCallback::OnResponse(const WriteClient * apWriteClient, const C
3838
}
3939
return;
4040
}
41-
else
42-
{
43-
// This is a response to another attribute write. Report the final result of last attribute write.
44-
callback->OnResponse(apWriteClient, mLastAttributePath.Value(), mAttributeStatus);
45-
}
41+
42+
// This is a response to another attribute write. Report the final result of last attribute write.
43+
callback->OnResponse(apWriteClient, mLastAttributePath.Value(), mAttributeStatus);
4644
}
4745

4846
// This is the first report for a new attribute. We assume it will never be a list item operation.

src/app/CommandHandler.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,8 @@ TLV::TLVWriter * CommandHandler::GetCommandDataIBTLVWriter()
546546
{
547547
return nullptr;
548548
}
549-
else
550-
{
551-
return mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().GetCommand().GetWriter();
552-
}
549+
550+
return mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().GetCommand().GetWriter();
553551
}
554552

555553
FabricIndex CommandHandler::GetAccessingFabricIndex() const

src/app/CommandSender.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,8 @@ TLV::TLVWriter * CommandSender::GetCommandDataIBTLVWriter()
372372
{
373373
return nullptr;
374374
}
375-
else
376-
{
377-
return mInvokeRequestBuilder.GetInvokeRequests().GetCommandData().GetWriter();
378-
}
375+
376+
return mInvokeRequestBuilder.GetInvokeRequests().GetCommandData().GetWriter();
379377
}
380378

381379
CHIP_ERROR CommandSender::HandleTimedStatus(const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload)

src/app/EventManagement.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ CHIP_ERROR EventManagement::CopyAndAdjustDeltaTime(const TLVReader & aReader, si
399399
// Does not go on the wire.
400400
return CHIP_NO_ERROR;
401401
}
402-
else if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kSystemTimestamp))) && !(ctx->mpContext->mFirst))
402+
if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kSystemTimestamp))) && !(ctx->mpContext->mFirst))
403403
{
404404
return ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp)),
405405
ctx->mpContext->mCurrentTime.mValue - ctx->mpContext->mPreviousTime.mValue);
@@ -501,12 +501,10 @@ CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, c
501501
{
502502
break;
503503
}
504-
else
505-
{
506-
buffer = buffer->GetNextCircularEventBuffer();
507-
assert(buffer != nullptr);
508-
// code guarantees that every PriorityLevel has a buffer destination.
509-
}
504+
505+
buffer = buffer->GetNextCircularEventBuffer();
506+
assert(buffer != nullptr);
507+
// code guarantees that every PriorityLevel has a buffer destination.
510508
}
511509

512510
mBytesWritten += writer.GetLengthWritten();

src/app/ReadClient.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -904,12 +904,11 @@ bool ReadClient::ResubscribeIfNeeded()
904904
ChipLogProgress(DataManagement, "Fail to resubscribe with error %" CHIP_ERROR_FORMAT, err.Format());
905905
return false;
906906
}
907-
else
908-
{
909-
ChipLogProgress(DataManagement,
910-
"Will try to Resubscribe to %02x:" ChipLogFormatX64 " at retry index %" PRIu32 " after %" PRIu32 "ms",
911-
mFabricIndex, ChipLogValueX64(mPeerNodeId), mNumRetries, intervalMsec);
912-
}
907+
908+
ChipLogProgress(DataManagement,
909+
"Will try to Resubscribe to %02x:" ChipLogFormatX64 " at retry index %" PRIu32 " after %" PRIu32 "ms",
910+
mFabricIndex, ChipLogValueX64(mPeerNodeId), mNumRetries, intervalMsec);
911+
913912
return true;
914913
}
915914

src/app/WriteClient.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,8 @@ CHIP_ERROR WriteClient::PutPreencodedAttribute(const ConcreteDataAttributePath &
322322
}
323323
return err;
324324
}
325-
else // We are writing a non-list attribute, or we are writing a single element of a list.
326-
{
327-
return PutSinglePreencodedAttributeWritePayload(attributePath, data);
328-
}
325+
// We are writing a non-list attribute, or we are writing a single element of a list.
326+
return PutSinglePreencodedAttributeWritePayload(attributePath, data);
329327
}
330328

331329
const char * WriteClient::GetStateStr() const

src/app/WriteClient.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,8 @@ class WriteClient : public Messaging::ExchangeDelegate
196196
attributePath.mClusterId, attributePath.mAttributeId, aDataVersion),
197197
value);
198198
}
199-
else
200-
{
201-
return EncodeAttribute(attributePath, value.Value());
202-
}
199+
200+
return EncodeAttribute(attributePath, value.Value());
203201
}
204202

205203
/**

src/app/data-model/DecodableList.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ class DecodableList
134134
{
135135
return CHIP_NO_ERROR;
136136
}
137-
else
138-
{
139-
return mStatus;
140-
}
137+
138+
return mStatus;
141139
}
142140

143141
private:
@@ -194,10 +192,8 @@ class DecodableList
194192
*size = 0;
195193
return CHIP_NO_ERROR;
196194
}
197-
else
198-
{
199-
return mReader.CountRemainingInContainer(size);
200-
}
195+
196+
return mReader.CountRemainingInContainer(size);
201197
}
202198

203199
CHIP_ERROR Decode(TLV::TLVReader & reader)

src/app/reporting/Engine.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -763,10 +763,9 @@ CHIP_ERROR Engine::ScheduleEventDelivery(ConcreteEventPath & aPath, uint32_t aBy
763763
ChipLogDetail(DataManagement, "urgent event schedule run");
764764
return ScheduleRun();
765765
}
766-
else
767-
{
768-
return ScheduleBufferPressureEventDelivery(aBytesWritten);
769-
}
766+
767+
return ScheduleBufferPressureEventDelivery(aBytesWritten);
768+
770769
return CHIP_NO_ERROR;
771770
}
772771

src/app/server/Server.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,9 @@ class Server
122122
{
123123
return CHIP_ERROR_INVALID_ARGUMENT;
124124
}
125-
else
126-
{
127-
// When size is zero, let's give a non-nullptr to the KVS backend
128-
buffer = &emptyPlaceholder;
129-
}
125+
126+
// When size is zero, let's give a non-nullptr to the KVS backend
127+
buffer = &emptyPlaceholder;
130128
}
131129

132130
size_t bytesRead = 0;

src/app/tests/suites/pics/PICSBooleanExpressionParser.cpp

+13-17
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,15 @@ bool PICSBooleanExpressionParser::EvaluateExpression(std::vector<std::string> &
115115
bool rightExpr = EvaluateExpression(tokens, PICS, index);
116116
return leftExpr && rightExpr;
117117
}
118-
else if (token == "||")
118+
if (token == "||")
119119
{
120120
index++;
121121
bool rightExpr = EvaluateExpression(tokens, PICS, index);
122122
return leftExpr || rightExpr;
123123
}
124-
else
125-
{
126-
ChipLogError(chipTool, "Unknown token: '%s'", token.c_str());
127-
chipDie();
128-
}
124+
125+
ChipLogError(chipTool, "Unknown token: '%s'", token.c_str());
126+
chipDie();
129127
}
130128

131129
bool PICSBooleanExpressionParser::EvaluateSubExpression(std::vector<std::string> & tokens, std::map<std::string, bool> & PICS,
@@ -145,23 +143,21 @@ bool PICSBooleanExpressionParser::EvaluateSubExpression(std::vector<std::string>
145143
index++;
146144
return expr;
147145
}
148-
else if (token == "!")
146+
if (token == "!")
149147
{
150148
index++;
151149
bool expr = EvaluateSubExpression(tokens, PICS, index);
152150
return !expr;
153151
}
154-
else
155-
{
156-
index++;
157152

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

165-
return PICS[token];
155+
if (PICS.find(token) == PICS.end())
156+
{
157+
// By default, let's consider that if a PICS item is not defined, it is |false|.
158+
// It allows to create a file that only contains enabled features.
159+
return false;
166160
}
161+
162+
return PICS[token];
167163
}

src/app/util/af-event.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,8 @@ EmberStatus emberAfEventControlSetDelayQS(EmberEventControl * control, uint32_t
195195
{
196196
return emberEventControlSetDelayMS(control, delayQs << 8);
197197
}
198-
else
199-
{
200-
return EMBER_BAD_ARGUMENT;
201-
}
198+
199+
return EMBER_BAD_ARGUMENT;
202200
}
203201

204202
EmberStatus emberAfEventControlSetDelayMinutes(EmberEventControl * control, uint16_t delayM)
@@ -207,10 +205,8 @@ EmberStatus emberAfEventControlSetDelayMinutes(EmberEventControl * control, uint
207205
{
208206
return emberEventControlSetDelayMS(control, static_cast<uint32_t>(delayM) << 16);
209207
}
210-
else
211-
{
212-
return EMBER_BAD_ARGUMENT;
213-
}
208+
209+
return EMBER_BAD_ARGUMENT;
214210
}
215211

216212
EmberStatus emberAfScheduleTickExtended(EndpointId endpoint, ClusterId clusterId, bool isClient, uint32_t delayMs,

src/app/util/attribute-storage.cpp

+20-28
Original file line numberDiff line numberDiff line change
@@ -370,19 +370,17 @@ EmberAfStatus emAfClusterPreAttributeChangedCallback(const app::ConcreteAttribut
370370
{
371371
return EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE;
372372
}
373-
else
373+
374+
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
375+
// Casting and calling a function pointer on the same line results in ignoring the return
376+
// of the call on gcc-arm-none-eabi-9-2019-q4-major
377+
EmberAfClusterPreAttributeChangedCallback f = (EmberAfClusterPreAttributeChangedCallback)(
378+
emberAfFindClusterFunction(cluster, CLUSTER_MASK_PRE_ATTRIBUTE_CHANGED_FUNCTION));
379+
if (f != NULL)
374380
{
375-
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
376-
// Casting and calling a function pointer on the same line results in ignoring the return
377-
// of the call on gcc-arm-none-eabi-9-2019-q4-major
378-
EmberAfClusterPreAttributeChangedCallback f = (EmberAfClusterPreAttributeChangedCallback)(
379-
emberAfFindClusterFunction(cluster, CLUSTER_MASK_PRE_ATTRIBUTE_CHANGED_FUNCTION));
380-
if (f != NULL)
381-
{
382-
status = f(attributePath, attributeType, size, value);
383-
}
384-
return status;
381+
status = f(attributePath, attributeType, size, value);
385382
}
383+
return status;
386384
}
387385

388386
static void initializeEndpoint(EmberAfDefinedEndpoint * definedEndpoint)
@@ -623,17 +621,15 @@ EmberAfStatus emAfReadOrWriteAttribute(EmberAfAttributeSearchRecord * attRecord,
623621
: emberAfExternalAttributeReadCallback(attRecord->endpoint, attRecord->clusterId,
624622
am, buffer, emberAfAttributeSize(am)));
625623
}
624+
625+
// Internal storage is only supported for fixed endpoints
626+
if (!isDynamicEndpoint)
627+
{
628+
return typeSensitiveMemCopy(attRecord->clusterId, dst, src, am, write, readLength);
629+
}
626630
else
627631
{
628-
// Internal storage is only supported for fixed endpoints
629-
if (!isDynamicEndpoint)
630-
{
631-
return typeSensitiveMemCopy(attRecord->clusterId, dst, src, am, write, readLength);
632-
}
633-
else
634-
{
635-
return EMBER_ZCL_STATUS_FAILURE;
636-
}
632+
return EMBER_ZCL_STATUS_FAILURE;
637633
}
638634
}
639635
}
@@ -750,10 +746,8 @@ bool emberAfContainsServerFromIndex(uint16_t index, ClusterId clusterId)
750746
{
751747
return false;
752748
}
753-
else
754-
{
755-
return emberAfFindClusterInType(emAfEndpoints[index].endpointType, clusterId, CLUSTER_MASK_SERVER);
756-
}
749+
750+
return emberAfFindClusterInType(emAfEndpoints[index].endpointType, clusterId, CLUSTER_MASK_SERVER);
757751
}
758752

759753
namespace chip {
@@ -797,10 +791,8 @@ const EmberAfCluster * emberAfFindCluster(EndpointId endpoint, ClusterId cluster
797791
{
798792
return NULL;
799793
}
800-
else
801-
{
802-
return emberAfFindClusterInType(emAfEndpoints[ep].endpointType, clusterId, mask);
803-
}
794+
795+
return emberAfFindClusterInType(emAfEndpoints[ep].endpointType, clusterId, mask);
804796
}
805797

806798
// Returns cluster within the endpoint; Does not ignore disabled endpoints

src/app/util/binding-table.cpp

+12-14
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,21 @@ CHIP_ERROR BindingTable::Add(const EmberBindingTableEntry & entry)
6464
mBindingTable[newIndex].type = EMBER_UNUSED_BINDING;
6565
return error;
6666
}
67+
68+
if (mTail == kNextNullIndex)
69+
{
70+
mTail = newIndex;
71+
mHead = newIndex;
72+
}
6773
else
6874
{
69-
if (mTail == kNextNullIndex)
70-
{
71-
mTail = newIndex;
72-
mHead = newIndex;
73-
}
74-
else
75-
{
76-
mNextIndex[mTail] = newIndex;
77-
mNextIndex[newIndex] = kNextNullIndex;
78-
mTail = newIndex;
79-
}
80-
81-
mSize++;
82-
return CHIP_NO_ERROR;
75+
mNextIndex[mTail] = newIndex;
76+
mNextIndex[newIndex] = kNextNullIndex;
77+
mTail = newIndex;
8378
}
79+
80+
mSize++;
81+
return CHIP_NO_ERROR;
8482
}
8583

8684
const EmberBindingTableEntry & BindingTable::GetAt(uint8_t index)

0 commit comments

Comments
 (0)