Skip to content

Commit c80ba35

Browse files
authored
nodiscard ChipError Batch project-chip#10: lib (project-chip#41868)
* Batch project-chip#10 nodiscard errors: lib * Review suggestions
1 parent 7ccaa37 commit c80ba35

File tree

15 files changed

+82
-64
lines changed

15 files changed

+82
-64
lines changed

src/lib/address_resolve/tool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class PrintOutNodeListener : public chip::AddressResolve::NodeListener
7474

7575
AddressResolve::NodeLookupHandle & Handle() { return mSelfHandle; }
7676

77-
void NotifyDone() { DeviceLayer::PlatformMgr().StopEventLoopTask(); }
77+
void NotifyDone() { TEMPORARY_RETURN_IGNORED DeviceLayer::PlatformMgr().StopEventLoopTask(); }
7878

7979
private:
8080
AddressResolve::NodeLookupHandle mSelfHandle;
@@ -142,14 +142,14 @@ bool Cmd_Node(int argc, const char ** argv)
142142
extern "C" void StopSignalHandler(int signal)
143143
{
144144
// no lint below because StopEventLoopTask is assumed to be async safe.
145-
DeviceLayer::PlatformMgr().StopEventLoopTask(); // NOLINT(bugprone-signal-handler)
145+
TEMPORARY_RETURN_IGNORED DeviceLayer::PlatformMgr().StopEventLoopTask(); // NOLINT(bugprone-signal-handler)
146146
}
147147

148148
} // namespace
149149

150150
int main(int argc, const char ** argv)
151151
{
152-
Platform::MemoryInit();
152+
TEMPORARY_RETURN_IGNORED Platform::MemoryInit();
153153

154154
signal(SIGTERM, StopSignalHandler);
155155
signal(SIGINT, StopSignalHandler);

src/lib/core/TLVCircularBuffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class DLL_EXPORT CircularTLVReader : public TLVReader
161161
* @param[in] buf A pointer to a fully initialized TLVCircularBuffer
162162
*
163163
*/
164-
void Init(TLVCircularBuffer & buf) { TLVReader::Init(buf, buf.DataLength()); }
164+
void Init(TLVCircularBuffer & buf) { TEMPORARY_RETURN_IGNORED TLVReader::Init(buf, buf.DataLength()); }
165165
};
166166

167167
class DLL_EXPORT CircularTLVWriter : public TLVWriter
@@ -182,7 +182,7 @@ class DLL_EXPORT CircularTLVWriter : public TLVWriter
182182
* @param[in] buf A pointer to a fully initialized TLVCircularBuffer
183183
*
184184
*/
185-
void Init(TLVCircularBuffer & buf) { TLVWriter::Init(buf, UINT32_MAX); }
185+
void Init(TLVCircularBuffer & buf) { TEMPORARY_RETURN_IGNORED TLVWriter::Init(buf, UINT32_MAX); }
186186
};
187187

188188
} // namespace TLV

src/lib/core/TLVVectorWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ constexpr uint32_t kIpv6MtuSize = 1280;
3434

3535
TlvVectorWriter::TlvVectorWriter(std::vector<uint8_t> & buffer) : mVectorBuffer(buffer)
3636
{
37-
Init(mVectorBuffer);
37+
TEMPORARY_RETURN_IGNORED Init(mVectorBuffer);
3838
}
3939

4040
TlvVectorWriter::~TlvVectorWriter() = default;

src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ CHIP_ERROR AdvertiserMinMdns::Init(chip::Inet::EndPointManager<chip::Inet::UDPEn
369369

370370
if (!mIsInitialized)
371371
{
372-
UpdateCommissionableInstanceName();
372+
TEMPORARY_RETURN_IGNORED UpdateCommissionableInstanceName();
373373
}
374374

375375
// Re-set the server in the response sender in case this has been swapped in the
@@ -554,8 +554,9 @@ CHIP_ERROR AdvertiserMinMdns::Advertise(const OperationalAdvertisingParameters &
554554
return CHIP_ERROR_NO_MEMORY;
555555
}
556556
}
557-
MakeServiceSubtype(nameBuffer, sizeof(nameBuffer),
558-
DiscoveryFilter(DiscoveryFilterType::kCompressedFabricId, params.GetPeerId().GetCompressedFabricId()));
557+
TEMPORARY_RETURN_IGNORED MakeServiceSubtype(
558+
nameBuffer, sizeof(nameBuffer),
559+
DiscoveryFilter(DiscoveryFilterType::kCompressedFabricId, params.GetPeerId().GetCompressedFabricId()));
559560
FullQName compressedFabricIdSubtype = operationalAllocator->AllocateQName(
560561
nameBuffer, kSubtypeServiceNamePart, kOperationalServiceName, kOperationalProtocol, kLocalDomain);
561562
VerifyOrReturnError(compressedFabricIdSubtype.nameCount != 0, CHIP_ERROR_NO_MEMORY);
@@ -673,7 +674,8 @@ CHIP_ERROR AdvertiserMinMdns::Advertise(const CommissionAdvertisingParameters &
673674

674675
if (const auto & vendorId = params.GetVendorId(); vendorId.has_value())
675676
{
676-
MakeServiceSubtype(nameBuffer, sizeof(nameBuffer), DiscoveryFilter(DiscoveryFilterType::kVendorId, *vendorId));
677+
TEMPORARY_RETURN_IGNORED MakeServiceSubtype(nameBuffer, sizeof(nameBuffer),
678+
DiscoveryFilter(DiscoveryFilterType::kVendorId, *vendorId));
677679
FullQName vendorServiceName =
678680
allocator->AllocateQName(nameBuffer, kSubtypeServiceNamePart, serviceType, kCommissionProtocol, kLocalDomain);
679681
VerifyOrReturnError(vendorServiceName.nameCount != 0, CHIP_ERROR_NO_MEMORY);
@@ -690,7 +692,8 @@ CHIP_ERROR AdvertiserMinMdns::Advertise(const CommissionAdvertisingParameters &
690692

691693
if (const auto & deviceType = params.GetDeviceType(); deviceType.has_value())
692694
{
693-
MakeServiceSubtype(nameBuffer, sizeof(nameBuffer), DiscoveryFilter(DiscoveryFilterType::kDeviceType, *deviceType));
695+
TEMPORARY_RETURN_IGNORED MakeServiceSubtype(nameBuffer, sizeof(nameBuffer),
696+
DiscoveryFilter(DiscoveryFilterType::kDeviceType, *deviceType));
694697
FullQName vendorServiceName =
695698
allocator->AllocateQName(nameBuffer, kSubtypeServiceNamePart, serviceType, kCommissionProtocol, kLocalDomain);
696699
VerifyOrReturnError(vendorServiceName.nameCount != 0, CHIP_ERROR_NO_MEMORY);
@@ -709,8 +712,9 @@ CHIP_ERROR AdvertiserMinMdns::Advertise(const CommissionAdvertisingParameters &
709712
if (params.GetCommissionAdvertiseMode() == CommssionAdvertiseMode::kCommissionableNode)
710713
{
711714
{
712-
MakeServiceSubtype(nameBuffer, sizeof(nameBuffer),
713-
DiscoveryFilter(DiscoveryFilterType::kShortDiscriminator, params.GetShortDiscriminator()));
715+
TEMPORARY_RETURN_IGNORED MakeServiceSubtype(
716+
nameBuffer, sizeof(nameBuffer),
717+
DiscoveryFilter(DiscoveryFilterType::kShortDiscriminator, params.GetShortDiscriminator()));
714718
FullQName shortServiceName =
715719
allocator->AllocateQName(nameBuffer, kSubtypeServiceNamePart, serviceType, kCommissionProtocol, kLocalDomain);
716720
VerifyOrReturnError(shortServiceName.nameCount != 0, CHIP_ERROR_NO_MEMORY);
@@ -726,8 +730,9 @@ CHIP_ERROR AdvertiserMinMdns::Advertise(const CommissionAdvertisingParameters &
726730
}
727731

728732
{
729-
MakeServiceSubtype(nameBuffer, sizeof(nameBuffer),
730-
DiscoveryFilter(DiscoveryFilterType::kLongDiscriminator, params.GetLongDiscriminator()));
733+
TEMPORARY_RETURN_IGNORED MakeServiceSubtype(
734+
nameBuffer, sizeof(nameBuffer),
735+
DiscoveryFilter(DiscoveryFilterType::kLongDiscriminator, params.GetLongDiscriminator()));
731736
FullQName longServiceName =
732737
allocator->AllocateQName(nameBuffer, kSubtypeServiceNamePart, serviceType, kCommissionProtocol, kLocalDomain);
733738
VerifyOrReturnError(longServiceName.nameCount != 0, CHIP_ERROR_NO_MEMORY);
@@ -743,7 +748,8 @@ CHIP_ERROR AdvertiserMinMdns::Advertise(const CommissionAdvertisingParameters &
743748

744749
if (params.GetCommissioningMode() != CommissioningMode::kDisabled)
745750
{
746-
MakeServiceSubtype(nameBuffer, sizeof(nameBuffer), DiscoveryFilter(DiscoveryFilterType::kCommissioningMode));
751+
TEMPORARY_RETURN_IGNORED MakeServiceSubtype(nameBuffer, sizeof(nameBuffer),
752+
DiscoveryFilter(DiscoveryFilterType::kCommissioningMode));
747753
FullQName longServiceName =
748754
allocator->AllocateQName(nameBuffer, kSubtypeServiceNamePart, serviceType, kCommissionProtocol, kLocalDomain);
749755
VerifyOrReturnError(longServiceName.nameCount != 0, CHIP_ERROR_NO_MEMORY);
@@ -792,7 +798,7 @@ FullQName AdvertiserMinMdns::GetOperationalTxtEntries(OperationalQueryAllocator:
792798
size_t numTxtFields = 0;
793799

794800
struct CommonTxtEntryStorage commonStorage;
795-
AddCommonTxtEntries<OperationalAdvertisingParameters>(params, commonStorage, txtFields, numTxtFields);
801+
TEMPORARY_RETURN_IGNORED AddCommonTxtEntries<OperationalAdvertisingParameters>(params, commonStorage, txtFields, numTxtFields);
796802
if (numTxtFields == 0)
797803
{
798804
return allocator->AllocateQNameFromArray(mEmptyTextEntries, 1);
@@ -840,7 +846,7 @@ FullQName AdvertiserMinMdns::GetCommissioningTxtEntries(const CommissionAdvertis
840846
txtFields[numTxtFields++] = txtDeviceName;
841847
}
842848
CommonTxtEntryStorage commonStorage;
843-
AddCommonTxtEntries<CommissionAdvertisingParameters>(params, commonStorage, txtFields, numTxtFields);
849+
TEMPORARY_RETURN_IGNORED AddCommonTxtEntries<CommissionAdvertisingParameters>(params, commonStorage, txtFields, numTxtFields);
844850

845851
// the following sub types only apply to commissionable node advertisements
846852
char txtDiscriminator[chip::Dnssd::kKeyLongDiscriminatorMaxLength + 3];

src/lib/dnssd/Discovery_ImplPlatform.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static void HandleNodeBrowse(void * context, DnssdService * services, size_t ser
113113
// check whether SRV, TXT and AAAA records were received in DNS responses
114114
else if (strlen(services[i].mHostName) == 0 || services[i].mTextEntrySize == 0 || !ipAddress.has_value())
115115
{
116-
ChipDnssdResolve(&services[i], services[i].mInterface, HandleNodeResolve, context);
116+
TEMPORARY_RETURN_IGNORED ChipDnssdResolve(&services[i], services[i].mInterface, HandleNodeResolve, context);
117117
}
118118
else
119119
{
@@ -391,7 +391,7 @@ void DnssdService::ToDiscoveredOperationalNodeBrowseData(DiscoveredNodeData & no
391391
{
392392
nodeData.Set<OperationalNodeBrowseData>();
393393

394-
ExtractIdFromInstanceName(mName, &nodeData.Get<OperationalNodeBrowseData>().peerId);
394+
TEMPORARY_RETURN_IGNORED ExtractIdFromInstanceName(mName, &nodeData.Get<OperationalNodeBrowseData>().peerId);
395395
nodeData.Get<OperationalNodeBrowseData>().hasZeroTTL = (mTtlSeconds == 0);
396396
}
397397

@@ -437,15 +437,8 @@ CHIP_ERROR DiscoveryImplPlatform::InitImpl()
437437
VerifyOrReturnError(mState == State::kUninitialized, CHIP_NO_ERROR);
438438
mState = State::kInitializing;
439439

440-
CHIP_ERROR err = ChipDnssdInit(HandleDnssdInit, HandleDnssdError, this);
441-
if (err != CHIP_NO_ERROR)
442-
{
443-
mState = State::kUninitialized;
444-
return err;
445-
}
446-
UpdateCommissionableInstanceName();
447-
448-
return CHIP_NO_ERROR;
440+
ReturnErrorOnFailure(ChipDnssdInit(HandleDnssdInit, HandleDnssdError, this), mState = State::kUninitialized);
441+
return UpdateCommissionableInstanceName();
449442
}
450443

451444
void DiscoveryImplPlatform::Shutdown()
@@ -466,15 +459,12 @@ void DiscoveryImplPlatform::HandleDnssdInit(void * context, CHIP_ERROR initError
466459
// Post an event that will start advertising
467460
DeviceLayer::ChipDeviceEvent event{ .Type = DeviceLayer::DeviceEventType::kDnssdInitialized };
468461

469-
CHIP_ERROR error = DeviceLayer::PlatformMgr().PostEvent(&event);
470-
if (error != CHIP_NO_ERROR)
471-
{
472-
ChipLogError(Discovery, "Posting DNS-SD platform initialized event failed with %" CHIP_ERROR_FORMAT, error.Format());
473-
}
462+
SuccessOrLog(DeviceLayer::PlatformMgr().PostEvent(&event), Discovery,
463+
"Posting DNS-SD platform initialized event failed with");
474464
}
475465
else
476466
{
477-
ChipLogError(Discovery, "DNS-SD initialization failed with %" CHIP_ERROR_FORMAT, initError.Format());
467+
ChipLogFailure(initError, Discovery, "DNS-SD initialization failed with");
478468
publisher->mState = State::kUninitialized;
479469
}
480470
}
@@ -722,7 +712,7 @@ void DiscoveryImplPlatform::NodeIdResolutionNoLongerNeeded(const PeerId & peerId
722712
CHIP_ERROR DiscoveryImplPlatform::DiscoverCommissionableNodes(DiscoveryFilter filter, DiscoveryContext & context)
723713
{
724714
ReturnErrorOnFailure(InitImpl());
725-
StopDiscovery(context);
715+
TEMPORARY_RETURN_IGNORED StopDiscovery(context);
726716

727717
if (filter.type == DiscoveryFilterType::kInstanceName)
728718
{
@@ -768,7 +758,7 @@ CHIP_ERROR DiscoveryImplPlatform::DiscoverCommissionableNodes(DiscoveryFilter fi
768758
CHIP_ERROR DiscoveryImplPlatform::DiscoverCommissioners(DiscoveryFilter filter, DiscoveryContext & context)
769759
{
770760
ReturnErrorOnFailure(InitImpl());
771-
StopDiscovery(context);
761+
TEMPORARY_RETURN_IGNORED StopDiscovery(context);
772762

773763
if (filter.type == DiscoveryFilterType::kInstanceName)
774764
{
@@ -812,7 +802,7 @@ CHIP_ERROR DiscoveryImplPlatform::DiscoverCommissioners(DiscoveryFilter filter,
812802
CHIP_ERROR DiscoveryImplPlatform::DiscoverOperational(DiscoveryFilter filter, DiscoveryContext & context)
813803
{
814804
ReturnErrorOnFailure(InitImpl());
815-
StopDiscovery(context);
805+
TEMPORARY_RETURN_IGNORED StopDiscovery(context);
816806

817807
char serviceName[kMaxOperationalServiceNameSize];
818808
ReturnErrorOnFailure(MakeServiceTypeName(serviceName, sizeof(serviceName), filter, DiscoveryType::kOperational));

src/lib/dnssd/Resolver_ImplMinimalMdns.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ void MinMdnsResolver::OnMdnsPacketData(const BytesRange & data, const chip::Inet
509509

510510
AdvancePendingResolverStates();
511511

512-
ScheduleRetries();
512+
TEMPORARY_RETURN_IGNORED ScheduleRetries();
513513
}
514514

515515
CHIP_ERROR MinMdnsResolver::Init(chip::Inet::EndPointManager<chip::Inet::UDPEndPoint> * udpEndPointManager)
@@ -785,7 +785,7 @@ CHIP_ERROR MinMdnsResolver::ScheduleRetries()
785785

786786
void MinMdnsResolver::RetryCallback(System::Layer *, void * self)
787787
{
788-
reinterpret_cast<MinMdnsResolver *>(self)->SendAllPendingQueries();
788+
TEMPORARY_RETURN_IGNORED reinterpret_cast<MinMdnsResolver *>(self)->SendAllPendingQueries();
789789
}
790790

791791
MinMdnsResolver gResolver;

src/lib/dnssd/Types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ struct CommissionNodeData : public CommonResolutionData
266266
if (rotatingIdLen > 0)
267267
{
268268
char rotatingIdString[chip::Dnssd::kMaxRotatingIdLen * 2 + 1] = "";
269-
Encoding::BytesToUppercaseHexString(rotatingId, rotatingIdLen, rotatingIdString, sizeof(rotatingIdString));
269+
TEMPORARY_RETURN_IGNORED Encoding::BytesToUppercaseHexString(rotatingId, rotatingIdLen, rotatingIdString,
270+
sizeof(rotatingIdString));
270271
ChipLogDetail(Discovery, "\tRotating ID: %s", rotatingIdString);
271272
}
272273
if (strlen(deviceName) != 0)

src/lib/dnssd/minimal_mdns/ResponseSender.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,12 @@ void ResponseSender::AddResponse(const ResourceRecord & record)
290290

291291
if (!mResponseBuilder.HasPacketBuffer())
292292
{
293-
mSendState.SetError(PrepareNewReplyPacket());
293+
TEMPORARY_RETURN_IGNORED mSendState.SetError(PrepareNewReplyPacket());
294294
ReturnOnFailure(mSendState.GetError());
295295
}
296-
297296
if (!mResponseBuilder.Ok())
298297
{
299-
mSendState.SetError(CHIP_ERROR_INCORRECT_STATE);
298+
TEMPORARY_RETURN_IGNORED mSendState.SetError(CHIP_ERROR_INCORRECT_STATE);
300299
return;
301300
}
302301

@@ -317,7 +316,7 @@ void ResponseSender::AddResponse(const ResourceRecord & record)
317316
{
318317
// Very much unexpected: single record addition should fit (our records should not be that big).
319318
ChipLogError(Discovery, "Failed to add single record to mDNS response.");
320-
mSendState.SetError(CHIP_ERROR_INTERNAL);
319+
TEMPORARY_RETURN_IGNORED mSendState.SetError(CHIP_ERROR_INTERNAL);
321320
}
322321
}
323322
}

src/lib/dnssd/minimal_mdns/Server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ CHIP_ERROR ServerBase::Listen(chip::Inet::EndPointManager<chip::Inet::UDPEndPoin
219219
if (err != CHIP_NO_ERROR)
220220
{
221221
char interfaceName[chip::Inet::InterfaceId::kMaxIfNameLength];
222-
interfaceId.GetInterfaceName(interfaceName, sizeof(interfaceName));
222+
TEMPORARY_RETURN_IGNORED interfaceId.GetInterfaceName(interfaceName, sizeof(interfaceName));
223223

224224
// Log only as non-fatal error. Failure to join will mean we reply to unicast queries only.
225225
ChipLogError(DeviceLayer, "MDNS failed to join multicast group on %s for address type %s: %" CHIP_ERROR_FORMAT,

src/lib/format/protocol_decoder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,27 +576,27 @@ void PayloadDecoderBase::NextFromValueRead(PayloadEntry & entry)
576576
switch (data->type)
577577
{
578578
case ItemType::kProtocolClusterId:
579-
mReader.Get(mClusterId);
579+
TEMPORARY_RETURN_IGNORED mReader.Get(mClusterId);
580580
mIMContentPosition.ResetToTop();
581581
mIMContentPosition.Enter(ByTag(ClusterTag(mClusterId)));
582582
info = mIMContentPosition.Get();
583583
break;
584584
case ItemType::kProtocolAttributeId:
585-
mReader.Get(mAttributeId);
585+
TEMPORARY_RETURN_IGNORED mReader.Get(mAttributeId);
586586
mIMContentPosition.ResetToTop();
587587
mIMContentPosition.Enter(ByTag(ClusterTag(mClusterId)));
588588
mIMContentPosition.Enter(ByTag(AttributeTag(mAttributeId)));
589589
info = mIMContentPosition.Get();
590590
break;
591591
case ItemType::kProtocolCommandId:
592-
mReader.Get(mCommandId);
592+
TEMPORARY_RETURN_IGNORED mReader.Get(mCommandId);
593593
mIMContentPosition.ResetToTop();
594594
mIMContentPosition.Enter(ByTag(ClusterTag(mClusterId)));
595595
mIMContentPosition.Enter(ByTag(CommandTag(mCommandId)));
596596
info = mIMContentPosition.Get();
597597
break;
598598
case ItemType::kProtocolEventId:
599-
mReader.Get(mEventId);
599+
TEMPORARY_RETURN_IGNORED mReader.Get(mEventId);
600600
mIMContentPosition.ResetToTop();
601601
mIMContentPosition.Enter(ByTag(ClusterTag(mClusterId)));
602602
mIMContentPosition.Enter(ByTag(EventTag(mEventId)));

0 commit comments

Comments
 (0)