Correct behavior for NSMutableData
's replaceBytes(in:withBytes:length:)
method
#735
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation
Previously,
replaceBytes(in:withBytes:length: 0)
was a no-op when called asdata.replaceBytes(in: range, withBytes: nil length: 0)
. This PR corrects this, and calls the underlyingCFDataReplaceBytes
in all cases. WhenreplacementBytes
isnil
andlength
is0
, this deletes the bytes inrange
.Scope
The scope of this change is limited to the single method noted above, and should be fully source compatible--only the internal implementation is changing.
SR Issue
SR-3404
Risk
There should be no risk to taking this change. Any code which relied on this call being a no-op did so in direct contradiction with the documentation.
Testing
A new test is also added to ensure that this method works as specified.
(Documentation taken from the NSMutableData API Reference)