Skip to content

Commit b367512

Browse files
Fix SkipArea logic and removed the use of memcpy (#35075)
* Updated the SkipArea serever handle to not error if the CurrentArea is null, according to the spec updates. * Replaced the use of memcpy with CopyCharSpanToMutableCharSpan. * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 7f84a48 commit b367512

File tree

2 files changed

+7
-30
lines changed

2 files changed

+7
-30
lines changed

src/app/clusters/service-area-server/service-area-cluster-objects.h

+7-21
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ struct AreaStructureWrapper : public chip::app::Clusters::ServiceArea::Structs::
110110
{
111111
areaDesc.locationInfo.SetNonNull();
112112
// Copy the name
113-
auto sizeToCopy = std::min(sizeof(mAreaNameBuffer), locationName.size());
114-
memcpy(mAreaNameBuffer, locationName.data(), sizeToCopy);
115-
areaDesc.locationInfo.Value().locationName = CharSpan(mAreaNameBuffer, sizeToCopy);
113+
auto areaNameSpan = MutableCharSpan(mAreaNameBuffer, kAreaNameMaxSize);
114+
CopyCharSpanToMutableCharSpan(locationName, areaNameSpan);
115+
areaDesc.locationInfo.Value().locationName = CharSpan(areaNameSpan.data(), areaNameSpan.size());
116116
areaDesc.locationInfo.Value().floorNumber = floorNumber;
117117
areaDesc.locationInfo.Value().areaType = areaType;
118118

@@ -320,24 +320,10 @@ struct MapStructureWrapper : public chip::app::Clusters::ServiceArea::Structs::M
320320
*/
321321
void Set(uint32_t aMapId, const CharSpan & aMapName)
322322
{
323-
mapID = aMapId;
324-
325-
if (aMapName.empty())
326-
{
327-
name = CharSpan(mMapNameBuffer, 0);
328-
}
329-
else if (aMapName.size() > sizeof(mMapNameBuffer))
330-
{
331-
// Save the truncated name that fits into available size.
332-
memcpy(mMapNameBuffer, aMapName.data(), sizeof(mMapNameBuffer));
333-
name = CharSpan(mMapNameBuffer, sizeof(mMapNameBuffer));
334-
}
335-
else
336-
{
337-
// Save full name.
338-
memcpy(mMapNameBuffer, aMapName.data(), aMapName.size());
339-
name = CharSpan(mMapNameBuffer, aMapName.size());
340-
}
323+
mapID = aMapId;
324+
auto mapNameSpan = MutableCharSpan(mMapNameBuffer, kMapNameMaxSize);
325+
CopyCharSpanToMutableCharSpan(aMapName, mapNameSpan);
326+
name = CharSpan(mapNameSpan.data(), mapNameSpan.size());
341327
}
342328

343329
/**

src/app/clusters/service-area-server/service-area-server.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,6 @@ void Instance::HandleSkipAreaCmd(HandlerContext & ctx, const Commands::SkipArea:
378378
return;
379379
}
380380

381-
// If the CurrentArea attribute is null, the status should be set to InvalidInMode.
382-
// If the Status field is not set to Success, or InvalidAreaList, the StatusText field SHALL include a vendor defined error
383-
// description.
384-
if (mCurrentArea.IsNull())
385-
{
386-
exitResponse(SkipAreaStatus::kInvalidInMode, "Current Area attribute is null"_span);
387-
return;
388-
}
389-
390381
// have the device attempt to skip
391382
// If the Status field is not set to Success, or InvalidAreaList, the StatusText field SHALL include a vendor defined error
392383
// description. InvalidInMode | The received request cannot be handled due to the current mode of the device. (skipStatusText to

0 commit comments

Comments
 (0)