Skip to content

Commit c561ace

Browse files
authored
nodiscard ChipError Batch project-chip#12: protocols (project-chip#41870)
* Batch project-chip#12 nodiscard errors: protocols * Review suggestions & fix CI * Address review suggestions * Fix clang tidy * Revert conversion from macro -> template as pw_unit_test does not support GoogleTest << and does not output template param
1 parent 8fbcc70 commit c561ace

16 files changed

+58
-53
lines changed

src/controller/ExamplePersistentStorage.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,19 +308,16 @@ CATValues PersistentStorage::GetCommissionerCATs()
308308
err = SyncGetKeyValue(kCommissionerCATsKey, serializedCATs, size);
309309
if (err == CHIP_NO_ERROR && size == chip::CATValues::kSerializedLength)
310310
{
311-
err = cats.Deserialize(serializedCATs);
312-
if (err == CHIP_NO_ERROR)
313-
{
314-
return cats;
315-
}
311+
cats.Deserialize(serializedCATs);
312+
return cats;
316313
}
317314
return chip::kUndefinedCATs;
318315
}
319316

320317
CHIP_ERROR PersistentStorage::SetCommissionerCATs(const CATValues & cats)
321318
{
322319
chip::CATValues::Serialized serializedCATs;
323-
ReturnErrorOnFailure(cats.Serialize(serializedCATs));
320+
cats.Serialize(serializedCATs);
324321

325322
return SyncSetKeyValue(kCommissionerCATsKey, serializedCATs, sizeof(serializedCATs));
326323
}

src/credentials/tests/TestChipCert.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,13 @@ TEST_F(TestChipCert, TestChipCert_ChipDN)
344344

345345
CATValues noc_cats2;
346346
chip::CATValues::Serialized serializedCATs;
347-
EXPECT_EQ(noc_cats.Serialize(serializedCATs), CHIP_NO_ERROR);
348-
EXPECT_EQ(noc_cats2.Deserialize(serializedCATs), CHIP_NO_ERROR);
347+
noc_cats.Serialize(serializedCATs);
348+
noc_cats2.Deserialize(serializedCATs);
349349
EXPECT_EQ(memcmp(&noc_cats, &noc_cats2, chip::CATValues::kSerializedLength), 0);
350350

351351
CATValues noc_cats3 = { { 0xABCD0001, 0xFFEEAA00, 0x0001F012 } };
352-
EXPECT_EQ(noc_cats3.Serialize(serializedCATs), CHIP_NO_ERROR);
353-
EXPECT_EQ(noc_cats2.Deserialize(serializedCATs), CHIP_NO_ERROR);
352+
noc_cats3.Serialize(serializedCATs);
353+
noc_cats2.Deserialize(serializedCATs);
354354
EXPECT_EQ(memcmp(&noc_cats3, &noc_cats2, chip::CATValues::kSerializedLength), 0);
355355
}
356356

src/lib/core/CASEAuthTag.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,24 +221,22 @@ struct CATValues
221221
static constexpr size_t kSerializedLength = kMaxSubjectCATAttributeCount * sizeof(CASEAuthTag);
222222
typedef uint8_t Serialized[kSerializedLength];
223223

224-
CHIP_ERROR Serialize(Serialized & outSerialized) const
224+
void Serialize(Serialized & outSerialized) const
225225
{
226226
uint8_t * p = outSerialized;
227227
for (size_t i = 0; i < kMaxSubjectCATAttributeCount; i++)
228228
{
229229
Encoding::LittleEndian::Write32(p, values[i]);
230230
}
231-
return CHIP_NO_ERROR;
232231
}
233232

234-
CHIP_ERROR Deserialize(const Serialized & inSerialized)
233+
void Deserialize(const Serialized & inSerialized)
235234
{
236235
const uint8_t * p = inSerialized;
237236
for (size_t i = 0; i < kMaxSubjectCATAttributeCount; i++)
238237
{
239238
values[i] = Encoding::LittleEndian::Read32(p);
240239
}
241-
return CHIP_NO_ERROR;
242240
}
243241
};
244242

src/protocols/bdx/AsyncTransferFacilitator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ CHIP_ERROR AsyncTransferFacilitator::OnMessageReceived(Messaging::ExchangeContex
149149

150150
// This should notify the transfer object to abort transfer so it can send a status report across the exchange
151151
// when we call ProcessOutputEvents below.
152-
mTransfer.AbortTransfer(GetBdxStatusCodeFromChipError(err));
152+
TEMPORARY_RETURN_IGNORED mTransfer.AbortTransfer(GetBdxStatusCodeFromChipError(err));
153153
}
154154
else if (!payloadHeader.HasMessageType(MessageType::BlockAckEOF))
155155
{
@@ -199,7 +199,7 @@ void AsyncResponder::NotifyEventHandled(const TransferSession::OutputEventType e
199199
{
200200
// If there was an error handling the output event, this should notify the transfer object to abort transfer
201201
// so it can send a status report across the exchange when we call ProcessOutputEvents below.
202-
mTransfer.AbortTransfer(GetBdxStatusCodeFromChipError(status));
202+
TEMPORARY_RETURN_IGNORED mTransfer.AbortTransfer(GetBdxStatusCodeFromChipError(status));
203203
}
204204

205205
ProcessOutputEvents();

src/protocols/bdx/BdxTransferDiagnosticLog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ CHIP_ERROR BdxTransferDiagnosticLog::OnMessageToSend(TransferSession::OutputEven
136136

137137
// If there's an error sending the message, close the exchange by calling Reset.
138138
auto err = mExchangeCtx->SendMessage(msgTypeData.ProtocolId, msgTypeData.MessageType, std::move(event.MsgData), sendFlags);
139-
VerifyOrDo(CHIP_NO_ERROR == err, OnTransferSessionEnd(err));
139+
VerifyOrDo(CHIP_NO_ERROR == err, TEMPORARY_RETURN_IGNORED OnTransferSessionEnd(err));
140140

141141
return err;
142142
}
@@ -197,7 +197,7 @@ void BdxTransferDiagnosticLog::OnExchangeClosing(Messaging::ExchangeContext * ec
197197
{
198198
// The exchange can be closing while TransferFacilitator is still accessing us, so
199199
// the BdxTransferDiagnosticLog can not be released "right now".
200-
mSystemLayer->ScheduleWork(
200+
TEMPORARY_RETURN_IGNORED mSystemLayer->ScheduleWork(
201201
[](auto * systemLayer, auto * appState) -> void {
202202
auto * _this = static_cast<BdxTransferDiagnosticLog *>(appState);
203203
_this->mPoolDelegate->Release(_this);

src/protocols/bdx/TransferFacilitator.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ void TransferFacilitator::PollForOutput()
9393
HandleTransferSessionOutput(outEvent);
9494

9595
VerifyOrReturn(mSystemLayer != nullptr, ChipLogError(BDX, "%s mSystemLayer is null", __FUNCTION__));
96-
mSystemLayer->StartTimer(mPollFreq, PollTimerHandler, this);
96+
TEMPORARY_RETURN_IGNORED mSystemLayer->StartTimer(mPollFreq, PollTimerHandler, this);
9797
}
9898

9999
void TransferFacilitator::ScheduleImmediatePoll()
100100
{
101101
VerifyOrReturn(mSystemLayer != nullptr, ChipLogError(BDX, "%s mSystemLayer is null", __FUNCTION__));
102-
mSystemLayer->StartTimer(System::Clock::Milliseconds32(kImmediatePollDelay), PollTimerHandler, this);
102+
TEMPORARY_RETURN_IGNORED mSystemLayer->StartTimer(System::Clock::Milliseconds32(kImmediatePollDelay), PollTimerHandler, this);
103103
}
104104

105105
CHIP_ERROR Responder::PrepareForTransfer(System::Layer * layer, TransferRole role, BitFlags<TransferControlFlags> xferControlOpts,
@@ -113,8 +113,7 @@ CHIP_ERROR Responder::PrepareForTransfer(System::Layer * layer, TransferRole rol
113113
ReturnErrorOnFailure(mTransfer.WaitForTransfer(role, xferControlOpts, maxBlockSize, timeout));
114114

115115
ChipLogProgress(BDX, "Start polling for messages");
116-
mSystemLayer->StartTimer(mPollFreq, PollTimerHandler, this);
117-
return CHIP_NO_ERROR;
116+
return mSystemLayer->StartTimer(mPollFreq, PollTimerHandler, this);
118117
}
119118

120119
CHIP_ERROR Initiator::InitiateTransfer(System::Layer * layer, TransferRole role, const TransferSession::TransferInitData & initData,
@@ -127,8 +126,7 @@ CHIP_ERROR Initiator::InitiateTransfer(System::Layer * layer, TransferRole role,
127126

128127
ReturnErrorOnFailure(mTransfer.StartTransfer(role, initData, timeout));
129128

130-
mSystemLayer->StartTimer(mPollFreq, PollTimerHandler, this);
131-
return CHIP_NO_ERROR;
129+
return mSystemLayer->StartTimer(mPollFreq, PollTimerHandler, this);
132130
}
133131

134132
} // namespace bdx

src/protocols/echo/EchoServer.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,14 @@ CHIP_ERROR EchoServer::Init(Messaging::ExchangeManager * exchangeMgr)
3838
OnEchoRequestReceived = nullptr;
3939

4040
// Register to receive unsolicited Echo Request messages from the exchange manager.
41-
mExchangeMgr->RegisterUnsolicitedMessageHandlerForType(MsgType::EchoRequest, this);
42-
43-
return CHIP_NO_ERROR;
41+
return mExchangeMgr->RegisterUnsolicitedMessageHandlerForType(MsgType::EchoRequest, this);
4442
}
4543

4644
void EchoServer::Shutdown()
4745
{
4846
if (mExchangeMgr != nullptr)
4947
{
50-
mExchangeMgr->UnregisterUnsolicitedMessageHandlerForType(MsgType::EchoRequest);
48+
TEMPORARY_RETURN_IGNORED mExchangeMgr->UnregisterUnsolicitedMessageHandlerForType(MsgType::EchoRequest);
5149
mExchangeMgr = nullptr;
5250
}
5351
}

src/protocols/secure_channel/CASEServer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ CHIP_ERROR CASEServer::ListenForSessionEstablishment(Messaging::ExchangeManager
5151
GetSession().SetGroupDataProvider(mGroupDataProvider);
5252

5353
ChipLogProgress(Inet, "CASE Server enabling CASE session setups");
54-
mExchangeManager->RegisterUnsolicitedMessageHandlerForType(Protocols::SecureChannel::MsgType::CASE_Sigma1, this);
54+
TEMPORARY_RETURN_IGNORED mExchangeManager->RegisterUnsolicitedMessageHandlerForType(
55+
Protocols::SecureChannel::MsgType::CASE_Sigma1, this);
5556

5657
PrepareForSessionEstablishment();
5758

src/protocols/secure_channel/CASEServer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class CASEServer : public SessionEstablishmentDelegate,
4444
{
4545
if (mExchangeManager != nullptr)
4646
{
47-
mExchangeManager->UnregisterUnsolicitedMessageHandlerForType(Protocols::SecureChannel::MsgType::CASE_Sigma1);
47+
TEMPORARY_RETURN_IGNORED mExchangeManager->UnregisterUnsolicitedMessageHandlerForType(
48+
Protocols::SecureChannel::MsgType::CASE_Sigma1);
4849
mExchangeManager = nullptr;
4950
}
5051

src/protocols/secure_channel/CASESession.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class CASESession::WorkHelper
317317
if (auto * session = helper->mSession.load())
318318
{
319319
// Execute callback in Matter thread; session should be OK with this
320-
(session->*(helper->mAfterWorkCallback))(helper->mData, helper->mStatus);
320+
TEMPORARY_RETURN_IGNORED(session->*(helper->mAfterWorkCallback))(helper->mData, helper->mStatus);
321321
}
322322
}
323323

@@ -973,7 +973,7 @@ CHIP_ERROR CASESession::FindLocalNodeFromDestinationId(const ByteSpan & destinat
973973
// Found a match, stop working, cache IPK, update local fabric context
974974
found = true;
975975
MutableByteSpan ipkSpan(mIPK);
976-
CopySpanToMutableSpan(candidateIpkSpan, ipkSpan);
976+
TEMPORARY_RETURN_IGNORED CopySpanToMutableSpan(candidateIpkSpan, ipkSpan);
977977
mFabricIndex = fabricInfo.GetFabricIndex();
978978
mLocalNodeId = nodeId;
979979
break;
@@ -1658,7 +1658,8 @@ CHIP_ERROR CASESession::ParseSigma2TBEData(ContiguousBufferTLVReader & decrypted
16581658
// tbsData2Signature's length should equal kMax_ECDSA_Signature_Length as per the Specification
16591659
size_t signatureLen = decryptedDataTlvReader.GetLength();
16601660
VerifyOrReturnError(outParsedSigma2TBE.tbsData2Signature.Capacity() == signatureLen, CHIP_ERROR_INVALID_TLV_ELEMENT);
1661-
outParsedSigma2TBE.tbsData2Signature.SetLength(signatureLen);
1661+
// Size checked above
1662+
RETURN_SAFELY_IGNORED outParsedSigma2TBE.tbsData2Signature.SetLength(signatureLen);
16621663
ReturnErrorOnFailure(decryptedDataTlvReader.GetBytes(outParsedSigma2TBE.tbsData2Signature.Bytes(),
16631664
outParsedSigma2TBE.tbsData2Signature.Length()));
16641665

@@ -2073,7 +2074,8 @@ CHIP_ERROR CASESession::ParseSigma3TBEData(ContiguousBufferTLVReader & decrypted
20732074
VerifyOrReturnError(decryptedDataTlvReader.GetTag() == AsTlvContextTag(TBEDataTags::kSignature), CHIP_ERROR_INVALID_TLV_TAG);
20742075
size_t signatureLen = decryptedDataTlvReader.GetLength();
20752076
VerifyOrReturnError(outHandleSigma3TBEData.tbsData3Signature.Capacity() == signatureLen, CHIP_ERROR_INVALID_TLV_ELEMENT);
2076-
outHandleSigma3TBEData.tbsData3Signature.SetLength(signatureLen);
2077+
// Size checked above
2078+
RETURN_SAFELY_IGNORED outHandleSigma3TBEData.tbsData3Signature.SetLength(signatureLen);
20772079
ReturnErrorOnFailure(decryptedDataTlvReader.GetBytes(outHandleSigma3TBEData.tbsData3Signature.Bytes(),
20782080
outHandleSigma3TBEData.tbsData3Signature.Length()));
20792081

0 commit comments

Comments
 (0)