Skip to content

Commit bbe2790

Browse files
committed
types need to match
1 parent f011ec1 commit bbe2790

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/app/tests/TestPowerSourceCluster.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apCo
127127
NL_TEST_ASSERT(apSuite, vec.size() == 0);
128128
}
129129

130-
if (powerSourceServer.GetNumSupportedEndpointLists() < 2)
130+
if (powerSourceServer.GetNumSupportedEndpointLists() < 2 ||
131+
powerSourceServer.GetNumSupportedEndpointLists() > std::numeric_limits<uint16_t>::max())
131132
{
132133
// Test assumes at least two endpoints. This runs on linux, not worthwhile to run on platforms with fewer endpoints.
133134
return;
@@ -140,6 +141,11 @@ void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apCo
140141
EndpointId list1[10] = { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
141142
EndpointId listRest[1] = { 2 };
142143

144+
// we checked earlier that this fit
145+
// This test just uses endpoints in order, so we want to set endpoints from
146+
// 0 to numEndpoints - 1, and use this for overflow checking
147+
EndpointId numEndpoints = static_cast<EndpointId>(powerSourceServer.GetNumSupportedEndpointLists());
148+
143149
// Endpoint 0 - list of 5
144150
err = powerSourceServer.SetEndpointList(0, Span<EndpointId>(list0));
145151
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
@@ -163,7 +169,7 @@ void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apCo
163169
}
164170

165171
// Remaining endpoints - list of 1
166-
for (EndpointId ep = 2; ep < powerSourceServer.GetNumSupportedEndpointLists(); ++ep)
172+
for (EndpointId ep = 2; ep < numEndpoints; ++ep)
167173
{
168174
err = powerSourceServer.SetEndpointList(ep, Span<EndpointId>(listRest));
169175
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
@@ -205,7 +211,7 @@ void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apCo
205211
}
206212

207213
// Remaining endpoints
208-
for (EndpointId ep = 2; ep < powerSourceServer.GetNumSupportedEndpointLists(); ++ep)
214+
for (EndpointId ep = 2; ep < numEndpoints; ++ep)
209215
{
210216
readBack = powerSourceServer.GetEndpointList(ep);
211217
NL_TEST_EXIT_ON_FAILED_ASSERT(apSuite, readBack != nullptr);
@@ -230,7 +236,7 @@ void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apCo
230236
}
231237

232238
// Ensure only the overwritten list was changed, using read interface
233-
for (EndpointId ep = 0; ep < powerSourceServer.GetNumSupportedEndpointLists() + 1; ++ep)
239+
for (EndpointId ep = 0; ep < numEndpoints + 1; ++ep)
234240
{
235241
std::vector<EndpointId> vec = ReadEndpointsThroughAttributeReader(apSuite, ep);
236242
if (ep == 0)
@@ -241,7 +247,7 @@ void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apCo
241247
NL_TEST_ASSERT(apSuite, vec[j] == list0[j]);
242248
}
243249
}
244-
else if (ep == powerSourceServer.GetNumSupportedEndpointLists())
250+
else if (ep == numEndpoints)
245251
{
246252
NL_TEST_ASSERT(apSuite, vec.size() == 0);
247253
}
@@ -258,7 +264,7 @@ void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apCo
258264
// *****************
259265
// Test removal
260266
// *****************
261-
for (EndpointId ep = 0; ep < powerSourceServer.GetNumSupportedEndpointLists(); ++ep)
267+
for (EndpointId ep = 0; ep < numEndpoints; ++ep)
262268
{
263269
err = powerSourceServer.SetEndpointList(ep, Span<EndpointId>());
264270
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
@@ -267,7 +273,7 @@ void TestPowerSourceCluster::TestEndpointList(nlTestSuite * apSuite, void * apCo
267273
}
268274

269275
// Check through the read interface
270-
for (EndpointId ep = 0; ep < powerSourceServer.GetNumSupportedEndpointLists() + 1; ++ep)
276+
for (EndpointId ep = 0; ep < numEndpoints + 1; ++ep)
271277
{
272278
std::vector<EndpointId> vec = ReadEndpointsThroughAttributeReader(apSuite, ep);
273279
NL_TEST_ASSERT(apSuite, vec.size() == 0);

0 commit comments

Comments
 (0)