Skip to content

Commit 6c54ab8

Browse files
authored
Enable several more clang-tidy checks. Fix a set of 'loop variable too small' errors. (#17690)
* enable more clang-tidy checks * Enable one more check * More enabled tests * Enable more checks and make codechanges to make it pass * Restyle * Fix compilation * One more compile failure * Update more tidy errors in tests * Mock attribute storage compile fixes * Add message to static assert * Undo emberAfClusterCount cast to uint8_t * More changes for emberAfClusterCount returning uint8_t * more updates for cluster count * Updated code for iteration over array size * one more review update * one more review update * Attempt to fix some non-null asserts by tidy * Adding one more nullable marker * Adding one more nullable marker * Fix nullable marker syntax for darwin compile * Update nullability markers again, this time darwin passes locally for all bridges * Disable constructor nullability linter for test command constructors as they seem broken * Move nolint for nullability into darwin-tool rather than main chip-tool
1 parent 5a0fbf4 commit 6c54ab8

File tree

25 files changed

+378
-58
lines changed

25 files changed

+378
-58
lines changed

.clang-tidy

-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ Checks: >
44
modernize-use-nullptr,
55
bugprone-*,
66
-bugprone-not-null-terminated-result,
7-
-bugprone-suspicious-memory-comparison,
8-
-bugprone-argument-comment,
97
-bugprone-unused-return-value,
108
-bugprone-branch-clone,
119
-bugprone-easily-swappable-parameters,
@@ -14,9 +12,7 @@ Checks: >
1412
-bugprone-forward-declaration-namespace,
1513
-bugprone-forwarding-reference-overload,
1614
-bugprone-undelegated-constructor,
17-
-bugprone-sizeof-expression,
1815
-bugprone-implicit-widening-of-multiplication-result,
19-
-bugprone-too-small-loop-variable,
2016
-bugprone-narrowing-conversions,
2117
-bugprone-misplaced-widening-cast,
2218
-bugprone-suspicious-include,
@@ -33,10 +29,8 @@ Checks: >
3329
-clang-analyzer-security.insecureAPI.strcpy,
3430
-clang-analyzer-nullability.NullablePassedToNonnull,
3531
-clang-analyzer-optin.performance.Padding,
36-
-clang-analyzer-unix.cstring.NullArg,
3732
-clang-analyzer-security.insecureAPI.rand,
3833
-clang-analyzer-core.NonNullParamChecker,
39-
-clang-analyzer-nullability.NullPassedToNonnull,
4034
-clang-analyzer-unix.Malloc,
4135
-clang-diagnostic-implicit-int-conversion
4236
WarningsAsErrors: '*'

examples/chip-tool-darwin/templates/tests/partials/test_cluster.zapt

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
class {{filename}}: public TestCommandBridge
33
{
44
public:
5+
// NOLINTBEGIN(clang-analyzer-nullability.NullPassedToNonnull): Test constructor nullability not enforced
56
{{#if ../credsIssuerConfigArg}}
67
{{filename}}(CredentialIssuerCommands * credsIssuerConfig): TestCommand("{{filename}}", credsIssuerConfig), mTestIndex(0)
78
{{else}}
@@ -16,6 +17,7 @@ class {{filename}}: public TestCommandBridge
1617
{{/if}}
1718
{{/chip_tests_config}}
1819
}
20+
// NOLINTEND(clang-analyzer-nullability.NullPassedToNonnull)
1921

2022
~{{filename}}()
2123
{

examples/common/pigweed/rpc_services/Descriptor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Descriptor : public pw_rpc::nanopb::Descriptor::Service<Descriptor>
9494
private:
9595
void ClusterList(EndpointId endpoint, bool server, ServerWriter<::chip_rpc_Cluster> & writer)
9696
{
97-
uint16_t cluster_count = emberAfClusterCount(endpoint, server);
97+
uint8_t cluster_count = emberAfClusterCount(endpoint, server);
9898

9999
for (uint8_t cluster_index = 0; cluster_index < cluster_count; cluster_index++)
100100
{

examples/shell/shell_common/cmd_server.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ static CHIP_ERROR CmdAppServerClusters(int argc, char ** argv)
172172

173173
for (int i = 0; i < emberAfEndpointCount(); i++)
174174
{
175-
EndpointId endpoint = emberAfEndpointFromIndex(i);
176-
uint16_t clusterCount = emberAfClusterCount(endpoint, server);
175+
EndpointId endpoint = emberAfEndpointFromIndex(i);
176+
177+
uint8_t clusterCount = emberAfClusterCount(endpoint, server);
177178

178179
streamer_printf(streamer_get(), "Endpoint %d:\r\n", endpoint);
179180

src/app/AttributePathExpandIterator.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ void AttributePathExpandIterator::PrepareAttributeIndexRange(const AttributePath
127127
// and overflow to 0 for the max index) to us not going through
128128
// non-metadata global attributes for this attribute.
129129
mGlobalAttributeIndex = UINT8_MAX;
130-
for (uint8_t idx = 0; idx < ArraySize(GlobalAttributesNotInMetadata); ++idx)
130+
131+
static_assert(ArraySize(GlobalAttributesNotInMetadata) <= UINT8_MAX, "Iterating over at most 256 array entries");
132+
133+
const uint8_t arraySize = static_cast<uint8_t>(ArraySize(GlobalAttributesNotInMetadata));
134+
for (uint8_t idx = 0; idx < arraySize; ++idx)
131135
{
132136
if (GlobalAttributesNotInMetadata[idx] == aAttributePath.mAttributeId)
133137
{

src/app/clusters/descriptor/descriptor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ CHIP_ERROR DescriptorAttrAccess::ReadDeviceAttribute(EndpointId endpoint, Attrib
124124
CHIP_ERROR DescriptorAttrAccess::ReadClientServerAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder, bool server)
125125
{
126126
CHIP_ERROR err = aEncoder.EncodeList([&endpoint, server](const auto & encoder) -> CHIP_ERROR {
127-
uint16_t clusterCount = emberAfClusterCount(endpoint, server);
127+
uint8_t clusterCount = emberAfClusterCount(endpoint, server);
128128

129129
for (uint8_t clusterIndex = 0; clusterIndex < clusterCount; clusterIndex++)
130130
{

src/app/clusters/door-lock-server/door-lock-server.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ bool DoorLockServer::findUserIndexByCredential(chip::EndpointId endpointId, DlCr
14231423
continue;
14241424
}
14251425

1426-
for (uint16_t j = 0; j < user.credentials.size(); ++j)
1426+
for (size_t j = 0; j < user.credentials.size(); ++j)
14271427
{
14281428
if (user.credentials.data()[j].CredentialIndex == credentialIndex &&
14291429
user.credentials.data()[j].CredentialType == to_underlying(credentialType))

src/app/clusters/ias-zone-server/ias-zone-server.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -628,13 +628,12 @@ static void unenrollSecurityDevice(EndpointId endpoint)
628628
void emberAfPluginIasZoneServerStackStatusCallback(EmberStatus status)
629629
{
630630
EndpointId endpoint;
631-
uint8_t i;
632631

633632
// If the device has left the network, unenroll all endpoints on the device
634633
// that are servers of the IAS Zone Cluster
635634
if (status == EMBER_NETWORK_DOWN && emberAfNetworkState() == EMBER_NO_NETWORK)
636635
{
637-
for (i = 0; i < emberAfEndpointCount(); i++)
636+
for (uint16_t i = 0; i < emberAfEndpointCount(); i++)
638637
{
639638
endpoint = emberAfEndpointFromIndex(i);
640639
if (emberAfContainsServer(endpoint, ZCL_IAS_ZONE_CLUSTER_ID))

src/app/clusters/test-cluster-server/test-cluster-server.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ CHIP_ERROR TestAttrAccess::WriteNullableStruct(AttributeValueDecoder & aDecoder)
233233
CHIP_ERROR TestAttrAccess::ReadListInt8uAttribute(AttributeValueEncoder & aEncoder)
234234
{
235235
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
236-
for (uint8_t index = 0; index < gListUint8DataLen; index++)
236+
for (size_t index = 0; index < gListUint8DataLen; index++)
237237
{
238238
ReturnErrorOnFailure(encoder.Encode(gListUint8Data[index]));
239239
}
@@ -281,7 +281,7 @@ CHIP_ERROR TestAttrAccess::WriteListInt8uAttribute(const ConcreteDataAttributePa
281281
CHIP_ERROR TestAttrAccess::ReadListOctetStringAttribute(AttributeValueEncoder & aEncoder)
282282
{
283283
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
284-
for (uint8_t index = 0; index < gListOctetStringDataLen; index++)
284+
for (size_t index = 0; index < gListOctetStringDataLen; index++)
285285
{
286286
ReturnErrorOnFailure(encoder.Encode(gListOctetStringData[index].AsSpan()));
287287
}
@@ -335,7 +335,7 @@ CHIP_ERROR TestAttrAccess::ReadListLongOctetStringAttribute(AttributeValueEncode
335335
// The ListOctetStringAttribute takes 512 bytes, and the whole attribute will exceed the IPv6 MTU, so we can test list chunking
336336
// feature with this attribute.
337337
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
338-
for (uint8_t index = 0; index < gListLongOctetStringLen; index++)
338+
for (size_t index = 0; index < gListLongOctetStringLen; index++)
339339
{
340340
ReturnErrorOnFailure(encoder.Encode(ByteSpan(chip::Uint8::from_const_char(sLongOctetStringBuf), 512)));
341341
}
@@ -381,7 +381,7 @@ CHIP_ERROR TestAttrAccess::WriteListLongOctetStringAttribute(const ConcreteDataA
381381
CHIP_ERROR TestAttrAccess::ReadListStructOctetStringAttribute(AttributeValueEncoder & aEncoder)
382382
{
383383
return aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
384-
for (uint8_t index = 0; index < gListOperationalCertLen; index++)
384+
for (size_t index = 0; index < gListOperationalCertLen; index++)
385385
{
386386
Structs::TestListStructOctet::Type structOctet;
387387
structOctet.fabricIndex = listStructOctetStringData[index].fabricIndex;

src/app/tests/TestPendingNotificationMap.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void TestAddRemove(nlTestSuite * aSuite, void * aContext)
7878
pendingMap.RemoveAllEntriesForNode(0, 0);
7979
uint8_t expectedEntryIndecies[] = { 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
8080
iter = pendingMap.begin();
81-
for (uint8_t i = 0; i < sizeof(expectedEntryIndecies); i++)
81+
for (size_t i = 0; i < sizeof(expectedEntryIndecies); i++)
8282
{
8383
PendingNotificationEntry entry = *iter;
8484
NL_TEST_ASSERT(aSuite, entry.mBindingEntryId == expectedEntryIndecies[i]);

src/app/util/attribute-storage.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static void initializeEndpoint(EmberAfDefinedEndpoint * definedEndpoint)
404404
// Calls the init functions.
405405
void emAfCallInits(void)
406406
{
407-
uint8_t index;
407+
uint16_t index;
408408
for (index = 0; index < emberAfEndpointCount(); index++)
409409
{
410410
if (emberAfEndpointIndexIsEnabled(index))
@@ -553,7 +553,7 @@ EmberAfStatus emAfReadOrWriteAttribute(EmberAfAttributeSearchRecord * attRecord,
553553

554554
uint16_t attributeOffsetIndex = 0;
555555

556-
for (uint8_t ep = 0; ep < emberAfEndpointCount(); ep++)
556+
for (uint16_t ep = 0; ep < emberAfEndpointCount(); ep++)
557557
{
558558
// Is this a dynamic endpoint?
559559
bool isDynamicEndpoint = (ep >= emberAfFixedEndpointCount());
@@ -702,7 +702,7 @@ const EmberAfCluster * emberAfFindClusterInType(const EmberAfEndpointType * endp
702702

703703
uint8_t emberAfClusterIndex(EndpointId endpoint, ClusterId clusterId, EmberAfClusterMask mask)
704704
{
705-
for (uint8_t ep = 0; ep < emberAfEndpointCount(); ep++)
705+
for (uint16_t ep = 0; ep < emberAfEndpointCount(); ep++)
706706
{
707707
// Check the endpoint id first, because that way we avoid examining the
708708
// endpoint type for endpoints that are not actually defined.

src/app/util/mock/attribute-storage.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,21 @@ uint16_t emberAfEndpointCount(void)
103103

104104
uint16_t emberAfIndexFromEndpoint(chip::EndpointId endpoint)
105105
{
106-
for (uint16_t i = 0; i < ArraySize(endpoints); i++)
106+
static_assert(ArraySize(endpoints) < UINT16_MAX, "Need to be able to return endpoint index as a 16-bit value.");
107+
108+
for (size_t i = 0; i < ArraySize(endpoints); i++)
107109
{
108110
if (endpoints[i] == endpoint)
109111
{
110-
return i;
112+
return static_cast<uint16_t>(i);
111113
}
112114
}
113115
return UINT16_MAX;
114116
}
115117

116118
uint8_t emberAfClusterCount(chip::EndpointId endpoint, bool server)
117119
{
118-
for (uint16_t i = 0; i < ArraySize(endpoints); i++)
120+
for (size_t i = 0; i < ArraySize(endpoints); i++)
119121
{
120122
if (endpoints[i] == endpoint)
121123
{
@@ -127,9 +129,9 @@ uint8_t emberAfClusterCount(chip::EndpointId endpoint, bool server)
127129

128130
uint16_t emberAfGetServerAttributeCount(chip::EndpointId endpoint, chip::ClusterId cluster)
129131
{
130-
uint16_t endpointIndex = emberAfIndexFromEndpoint(endpoint);
131-
uint16_t clusterCountOnEndpoint = emberAfClusterCount(endpoint, true);
132-
for (uint16_t i = 0; i < clusterCountOnEndpoint; i++)
132+
uint16_t endpointIndex = emberAfIndexFromEndpoint(endpoint);
133+
uint8_t clusterCountOnEndpoint = emberAfClusterCount(endpoint, true);
134+
for (uint8_t i = 0; i < clusterCountOnEndpoint; i++)
133135
{
134136
if (clusters[i + clusterIndex[endpointIndex]] == cluster)
135137
{
@@ -142,9 +144,9 @@ uint16_t emberAfGetServerAttributeCount(chip::EndpointId endpoint, chip::Cluster
142144
uint16_t emberAfGetServerAttributeIndexByAttributeId(chip::EndpointId endpoint, chip::ClusterId cluster,
143145
chip::AttributeId attributeId)
144146
{
145-
uint16_t endpointIndex = emberAfIndexFromEndpoint(endpoint);
146-
uint16_t clusterCountOnEndpoint = emberAfClusterCount(endpoint, true);
147-
for (uint16_t i = 0; i < clusterCountOnEndpoint; i++)
147+
uint16_t endpointIndex = emberAfIndexFromEndpoint(endpoint);
148+
uint8_t clusterCountOnEndpoint = emberAfClusterCount(endpoint, true);
149+
for (uint8_t i = 0; i < clusterCountOnEndpoint; i++)
148150
{
149151
if (clusters[i + clusterIndex[endpointIndex]] == cluster)
150152
{
@@ -180,9 +182,9 @@ chip::Optional<chip::ClusterId> emberAfGetNthClusterId(chip::EndpointId endpoint
180182
chip::Optional<chip::AttributeId> emberAfGetServerAttributeIdByIndex(chip::EndpointId endpoint, chip::ClusterId cluster,
181183
uint16_t index)
182184
{
183-
uint16_t endpointIndex = emberAfIndexFromEndpoint(endpoint);
184-
uint16_t clusterCountOnEndpoint = emberAfClusterCount(endpoint, true);
185-
for (uint16_t i = 0; i < clusterCountOnEndpoint; i++)
185+
uint16_t endpointIndex = emberAfIndexFromEndpoint(endpoint);
186+
uint8_t clusterCountOnEndpoint = emberAfClusterCount(endpoint, true);
187+
for (uint8_t i = 0; i < clusterCountOnEndpoint; i++)
186188
{
187189
if (clusters[i + clusterIndex[endpointIndex]] == cluster)
188190
{
@@ -199,8 +201,8 @@ chip::Optional<chip::AttributeId> emberAfGetServerAttributeIdByIndex(chip::Endpo
199201

200202
uint8_t emberAfClusterIndex(chip::EndpointId endpoint, chip::ClusterId cluster, EmberAfClusterMask mask)
201203
{
202-
uint16_t endpointIndex = emberAfIndexFromEndpoint(endpoint);
203-
uint16_t clusterCountOnEndpoint = emberAfClusterCount(endpoint, true);
204+
uint16_t endpointIndex = emberAfIndexFromEndpoint(endpoint);
205+
uint8_t clusterCountOnEndpoint = emberAfClusterCount(endpoint, true);
204206
for (uint8_t i = 0; i < clusterCountOnEndpoint; i++)
205207
{
206208
if (clusters[i + clusterIndex[endpointIndex]] == cluster)

src/app/util/util.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ int8_t emberAfCompareValues(const uint8_t * val1, const uint8_t * val2, uint16_t
520520
// no length means nothing to compare. Shouldn't even happen, since len is sizeof(some-integer-type).
521521
return 0;
522522
}
523-
uint8_t i, j, k;
523+
524524
if (signedNumber)
525525
{ // signed number comparison
526526
if (len <= 4)
@@ -529,12 +529,12 @@ int8_t emberAfCompareValues(const uint8_t * val1, const uint8_t * val2, uint16_t
529529
int32_t accum2 = 0x0;
530530
int32_t all1s = -1;
531531

532-
for (i = 0; i < len; i++)
532+
for (uint16_t i = 0; i < len; i++)
533533
{
534-
j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i]));
534+
uint8_t j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i]));
535535
accum1 |= j << (8 * (len - 1 - i));
536536

537-
k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]);
537+
uint8_t k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]);
538538
accum2 |= k << (8 * (len - 1 - i));
539539
}
540540

@@ -568,10 +568,10 @@ int8_t emberAfCompareValues(const uint8_t * val1, const uint8_t * val2, uint16_t
568568
}
569569

570570
// regular unsigned number comparison
571-
for (i = 0; i < len; i++)
571+
for (uint16_t i = 0; i < len; i++)
572572
{
573-
j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i]));
574-
k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]);
573+
uint8_t j = (val1 == nullptr ? 0 : (EM_BIG_ENDIAN ? val1[i] : val1[(len - 1) - i]));
574+
uint8_t k = (EM_BIG_ENDIAN ? val2[i] : val2[(len - 1) - i]);
575575

576576
if (j > k)
577577
{

src/credentials/CHIPCert.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ CHIP_ERROR ExtractCATsFromOpCert(const ChipCertificateData & opcert, CATValues &
12331233
cats.values[catCount++] = static_cast<CASEAuthTag>(rdn.mChipVal);
12341234
}
12351235
}
1236-
for (uint8_t i = catCount; i < cats.size(); ++i)
1236+
for (size_t i = catCount; i < cats.size(); ++i)
12371237
{
12381238
cats.values[i] = kUndefinedCAT;
12391239
}

src/darwin/Framework/CHIP/CHIPAttestationTrustStoreBridge.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CHIPAttestationTrustStoreBridge : public chip::Credentials::AttestationTru
3030
const chip::ByteSpan & skid, chip::MutableByteSpan & outPaaDerBuffer) const override;
3131

3232
private:
33-
NSArray<NSData *> * mPaaCerts;
33+
NSArray<NSData *> * _Nullable mPaaCerts;
3434
};
3535

3636
NS_ASSUME_NONNULL_END

src/darwin/Framework/CHIP/CHIPDevicePairingDelegateBridge.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class CHIPDevicePairingDelegateBridge : public chip::Controller::DevicePairingDe
4040
void OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR error) override;
4141

4242
private:
43-
id<CHIPDevicePairingDelegate> mDelegate;
44-
dispatch_queue_t mQueue;
43+
_Nullable id<CHIPDevicePairingDelegate> mDelegate;
44+
_Nullable dispatch_queue_t mQueue;
4545

4646
CHIPPairingStatus MapStatus(chip::Controller::DevicePairingDelegate::Status status);
4747
};

src/darwin/Framework/CHIP/CHIPP256KeypairBridge.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CHIPP256KeypairBridge : public chip::Crypto::P256KeypairBase
4949
const chip::Crypto::P256PublicKey & Pubkey() const override { return mPubkey; };
5050

5151
private:
52-
id<CHIPKeypair> mKeypair;
52+
id<CHIPKeypair> _Nullable mKeypair;
5353
chip::Crypto::P256PublicKey mPubkey;
5454

5555
CHIP_ERROR setPubkey();

src/darwin/Framework/CHIP/CHIPPersistentStorageDelegateBridge.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ class CHIPPersistentStorageDelegateBridge : public chip::PersistentStorageDelega
3535
CHIP_ERROR SyncDeleteKeyValue(const char * key) override;
3636

3737
private:
38-
id<CHIPPersistentStorageDelegate> mDelegate;
39-
40-
dispatch_queue_t mWorkQueue;
38+
_Nullable id<CHIPPersistentStorageDelegate> mDelegate;
39+
_Nullable dispatch_queue_t mWorkQueue;
4140
};
4241

4342
NS_ASSUME_NONNULL_END

src/lib/dnssd/tests/TestTxtFields.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void TestGetRotatingDeviceId(nlTestSuite * inSuite, void * inContext)
232232
strcpy(ri, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F3031");
233233
GetRotatingDeviceId(GetSpan(ri), id, &len);
234234
NL_TEST_ASSERT(inSuite, len == sizeof(id));
235-
for (uint8_t i = 0; i < sizeof(id); ++i)
235+
for (size_t i = 0; i < sizeof(id); ++i)
236236
{
237237
NL_TEST_ASSERT(inSuite, id[i] == i);
238238
}

src/lib/shell/streamer.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ ssize_t ENFORCE_FORMAT(2, 0) streamer_vprintf(streamer_t * self, const char * fm
5757

5858
// vsnprintf doesn't return negative numbers as long as the length it's
5959
// passed fits in INT_MAX.
60+
// NOLINTNEXTLINE(bugprone-sizeof-expression)
6061
static_assert(sizeof(buf) <= INT_MAX, "Return value cast not valid");
6162
len = static_cast<unsigned int>(vsnprintf(buf, sizeof(buf), fmt, ap));
6263
if (len >= sizeof(buf))

src/lib/support/tests/TestFixedBufferAllocator.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ void TestClone(nlTestSuite * inSuite, void * inContext)
3636

3737
NL_TEST_ASSERT(inSuite, allocatedString != nullptr);
3838
NL_TEST_ASSERT(inSuite, allocatedString != kTestString);
39+
40+
// NOLINTNEXTLINE(clang-analyzer-unix.cstring.NullArg): null check for allocated string already done
3941
NL_TEST_ASSERT(inSuite, strcmp(allocatedString, kTestString) == 0);
4042

4143
const uint8_t kTestData[] = { 0xDE, 0xAD, 0xBE, 0xEF };
4244
const uint8_t * allocatedData = alloc.Clone(kTestData, sizeof(kTestData));
4345

4446
NL_TEST_ASSERT(inSuite, allocatedData != nullptr);
4547
NL_TEST_ASSERT(inSuite, allocatedData != kTestData);
48+
49+
// NOLINTNEXTLINE(clang-analyzer-unix.cstring.NullArg): null check for allocated data already done
4650
NL_TEST_ASSERT(inSuite, memcmp(allocatedData, kTestData, sizeof(kTestData)) == 0);
4751
}
4852

src/setup_payload/Base38Encode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ CHIP_ERROR base38Encode(ByteSpan in_buf, MutableCharSpan & out_buf)
5555

5656
size_t bytesInChunk = (in_buf_len >= kMaxBytesSingleChunkLen) ? kMaxBytesSingleChunkLen : in_buf_len;
5757

58-
for (uint8_t byte_idx = 0; byte_idx < bytesInChunk; byte_idx++)
58+
for (size_t byte_idx = 0; byte_idx < bytesInChunk; byte_idx++)
5959
{
6060
value += static_cast<uint32_t>(in_buf_ptr[byte_idx] << (8 * byte_idx));
6161
}

0 commit comments

Comments
 (0)