-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fix SkipArea logic and removed the use of memcpy #35075
Changes from all commits
0bdbd39
3db7adf
3e108d0
03718aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this has different behavior from the old code, right? The old code copied as much as fit. I think the code above also has that problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for spotting this @bzbarsky-apple. I did not check the implementation of this method. @cecille, ideally this method does not error as otherwise setting these values by simply using consecutive |
||
name = CharSpan(mapNameSpan.data(), mapNameSpan.size()); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, that last line could just have been: