1
- /* *
1
+ m /* *
2
2
*
3
3
* Copyright (c) 2020 Project CHIP Authors
4
4
*
@@ -263,8 +263,8 @@ Status AttributeValueIsChanging(EndpointId endpoint, ClusterId cluster, Attribut
263
263
// We don't know how to size our buffer for strings in general, but if the
264
264
// string happens to fit into our fixed-size buffer, great.
265
265
size_t valueSize = metadata->size ;
266
- constexpr size_t maxValueSize = 16 ; // ipv6adr
267
- if (valueSize > maxValueSize )
266
+ constexpr size_t kMaxValueSize = 16 ; // ipv6adr
267
+ if (valueSize > kMaxValueSize )
268
268
{
269
269
if (emberAfIsStringAttributeType (attributeType) || emberAfIsLongStringAttributeType (attributeType))
270
270
{
@@ -279,8 +279,8 @@ Status AttributeValueIsChanging(EndpointId endpoint, ClusterId cluster, Attribut
279
279
return Status::ConstraintError;
280
280
}
281
281
282
- uint8_t oldValueBuffer[maxValueSize ];
283
- // Cast to uint16_t is safe, because we checked valueSize <= maxValueSize above.
282
+ uint8_t oldValueBuffer[kMaxValueSize ];
283
+ // Cast to uint16_t is safe, because we checked valueSize <= kMaxValueSize above.
284
284
if (emberAfReadAttribute (endpoint, cluster, attributeID, oldValueBuffer, static_cast <uint16_t >(valueSize)) != Status::Success)
285
285
{
286
286
// We failed to read the old value, so flag the value as changing to be safe.
@@ -292,12 +292,18 @@ Status AttributeValueIsChanging(EndpointId endpoint, ClusterId cluster, Attribut
292
292
{
293
293
size_t oldLength = emberAfStringLength (oldValueBuffer);
294
294
size_t newLength = emberAfStringLength (newValueData);
295
+ // The first byte of the buffer is the string length, so comparing
296
+ // oldLength to newLength handles comparing that byte, and the oldLength
297
+ // bytes of actual data start one byte into the buffer.
295
298
*isChanging = (oldLength != newLength) || (memcmp (oldValueBuffer + 1 , newValueData + 1 , oldLength) != 0 );
296
299
}
297
300
else if (emberAfIsLongStringAttributeType (attributeType))
298
301
{
299
302
size_t oldLength = emberAfLongStringLength (oldValueBuffer);
300
303
size_t newLength = emberAfLongStringLength (newValueData);
304
+ // The first two bytes of the buffer are the string length, so comparing
305
+ // oldLength to newLength handles comparing those bytes, and the oldLength
306
+ // bytes of actual data start two bytes into the buffer.
301
307
*isChanging = (oldLength != newLength) || (memcmp (oldValueBuffer + 2 , newValueData + 2 , oldLength) != 0 );
302
308
}
303
309
else
0 commit comments