Skip to content

[Foundation] Fix Data.count’s setter #28919

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

Merged
merged 1 commit into from
Jan 9, 2020

Conversation

lorentey
Copy link
Member

Data provides a settable count property. Its expected behavior is undocumented, but based on the implementation, it is intended to zero-extend (or truncate) the collection to the specified length.

This does not work correctly if we start with an empty Data and we try to increase the count by a small integer:

import Foundation

var d = Data()
d.count = 2
print(d.count) // ⟹ 0 ⁉️

d.count = 100
print(d.count) // ⟹ 100 ✓

It looks like this bug was introduced with the Data overhaul that shipped in Swift 5.

(This issue was uncovered by #28918.)

rdar://58134026

Data provides a settable `count` property. Its expected behavior is undocumented, but based on the implementation, it is intended to zero-extend (or truncate) the collection to the specified length.

This does not work correctly if we start with an empty Data and we try to increase the count by a small integer:

```
import Foundation

var d = Data()
d.count = 2
print(d.count) // ⟹ 0 ⁉️

d.count = 100
print(d.count) // ⟹ 100 ✓
```

It looks like this bug was introduced with the Data overhaul that shipped in Swift 5.

(This issue was uncovered by swiftlang#28918.)

rdar://58134026
@lorentey
Copy link
Member Author

@swift-ci test

@phausler
Copy link
Contributor

phausler commented Jan 9, 2020

Looks good to me. Good catch: thanks!

@phausler
Copy link
Contributor

phausler commented Jan 9, 2020

This probably should also be applied to sclf too

@lorentey
Copy link
Member Author

lorentey commented Jan 9, 2020

Merging. It looks like corelibs-Foundation indeed has the same issue -- I'll submit a patch in a jiffy.

@lorentey lorentey merged commit 5c2095e into swiftlang:master Jan 9, 2020
@lorentey lorentey deleted the fix-Data.count-setter branch January 11, 2020 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants