Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix SkipArea logic and removed the use of memcpy (#35075)
Browse files Browse the repository at this point in the history
* 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>
2 people authored and pull[bot] committed Oct 22, 2024
1 parent 8733bb9 commit 1033414
Showing 2 changed files with 7 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -110,9 +110,9 @@ struct AreaStructureWrapper : public chip::app::Clusters::ServiceArea::Structs::
{
areaDesc.locationInfo.SetNonNull();
// Copy the name
auto sizeToCopy = std::min(sizeof(mAreaNameBuffer), locationName.size());
memcpy(mAreaNameBuffer, locationName.data(), sizeToCopy);
areaDesc.locationInfo.Value().locationName = CharSpan(mAreaNameBuffer, sizeToCopy);
auto areaNameSpan = MutableCharSpan(mAreaNameBuffer, kAreaNameMaxSize);
CopyCharSpanToMutableCharSpan(locationName, areaNameSpan);
areaDesc.locationInfo.Value().locationName = CharSpan(areaNameSpan.data(), areaNameSpan.size());
areaDesc.locationInfo.Value().floorNumber = floorNumber;
areaDesc.locationInfo.Value().areaType = areaType;

@@ -320,24 +320,10 @@ struct MapStructureWrapper : public chip::app::Clusters::ServiceArea::Structs::M
*/
void Set(uint32_t aMapId, const CharSpan & aMapName)
{
mapID = aMapId;

if (aMapName.empty())
{
name = CharSpan(mMapNameBuffer, 0);
}
else if (aMapName.size() > sizeof(mMapNameBuffer))
{
// Save the truncated name that fits into available size.
memcpy(mMapNameBuffer, aMapName.data(), sizeof(mMapNameBuffer));
name = CharSpan(mMapNameBuffer, sizeof(mMapNameBuffer));
}
else
{
// Save full name.
memcpy(mMapNameBuffer, aMapName.data(), aMapName.size());
name = CharSpan(mMapNameBuffer, aMapName.size());
}
mapID = aMapId;
auto mapNameSpan = MutableCharSpan(mMapNameBuffer, kMapNameMaxSize);
CopyCharSpanToMutableCharSpan(aMapName, mapNameSpan);
name = CharSpan(mapNameSpan.data(), mapNameSpan.size());
}

/**
9 changes: 0 additions & 9 deletions src/app/clusters/service-area-server/service-area-server.cpp
Original file line number Diff line number Diff line change
@@ -378,15 +378,6 @@ void Instance::HandleSkipAreaCmd(HandlerContext & ctx, const Commands::SkipArea:
return;
}

// If the CurrentArea attribute is null, the status should be set to InvalidInMode.
// If the Status field is not set to Success, or InvalidAreaList, the StatusText field SHALL include a vendor defined error
// description.
if (mCurrentArea.IsNull())
{
exitResponse(SkipAreaStatus::kInvalidInMode, "Current Area attribute is null"_span);
return;
}

// have the device attempt to skip
// If the Status field is not set to Success, or InvalidAreaList, the StatusText field SHALL include a vendor defined error
// description. InvalidInMode | The received request cannot be handled due to the current mode of the device. (skipStatusText to

0 comments on commit 1033414

Please sign in to comment.