Skip to content

Commit

Permalink
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 <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Aug 29, 2024
1 parent 2190201 commit 4637345
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}

/**
Expand Down
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
Expand Up @@ -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
Expand Down

0 comments on commit 4637345

Please sign in to comment.