Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate map and area names #35127

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/app/clusters/service-area-server/service-area-cluster-objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ struct AreaStructureWrapper : public chip::app::Clusters::ServiceArea::Structs::
const DataModel::Nullable<Globals::AreaTypeTag> & areaType)
{
areaDesc.locationInfo.SetNonNull();
// Copy the name
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;

// Copy the name. If the name is larger than kAreaNameMaxSize, truncate it to fit.
auto sizeToCopy = std::min(kAreaNameMaxSize, locationName.size());
memcpy(mAreaNameBuffer, locationName.data(), sizeToCopy);
areaDesc.locationInfo.Value().locationName = CharSpan(mAreaNameBuffer, sizeToCopy);

areaDesc.locationInfo.Value().floorNumber = floorNumber;
areaDesc.locationInfo.Value().areaType = areaType;

return *this;
}
Expand Down Expand Up @@ -320,10 +322,11 @@ struct MapStructureWrapper : public chip::app::Clusters::ServiceArea::Structs::M
*/
void Set(uint32_t aMapId, const CharSpan & aMapName)
{
mapID = aMapId;
auto mapNameSpan = MutableCharSpan(mMapNameBuffer, kMapNameMaxSize);
CopyCharSpanToMutableCharSpan(aMapName, mapNameSpan);
name = CharSpan(mapNameSpan.data(), mapNameSpan.size());
mapID = aMapId;
// Copy the name. If the name is larger than kMapNameMaxSize, truncate it to fit.
auto sizeToCopy = std::min(kMapNameMaxSize, aMapName.size());
memcpy(mMapNameBuffer, aMapName.data(), sizeToCopy);
name = CharSpan(mMapNameBuffer, sizeToCopy);
}

/**
Expand Down
Loading