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

Leaving Array's buffer uninitialised is breach of contract #39

Open
valeriyvan opened this issue Nov 30, 2022 · 1 comment
Open

Leaving Array's buffer uninitialised is breach of contract #39

valeriyvan opened this issue Nov 30, 2022 · 1 comment

Comments

@valeriyvan
Copy link

https://github.com/kelvin13/swift-png/blob/075dfb248ae327822635370e9d4f94a5d3fe93b2/sources/png/decoder.swift#L289

https://developer.apple.com/documentation/swift/array/init(unsafeuninitializedcapacity:initializingwith:):

Discussion

Inside the closure, set the initializedCount parameter to the number of elements that are initialized by the closure. The memory in the range buffer[0..<initializedCount] must be initialized at the end of the closure’s execution, and the memory in the range buffer[initializedCount...] must be uninitialized. This postcondition must hold even if the initializer closure throws an error.

@tayloraswift
Copy link
Owner

this is only a breach-of-contract in the generic case; because UInt8 is a trivial type, it should be perfectly valid to leave the memory uninitialized. i am reluctant to have PNG.Data.Rectangular be backed by a managed buffer or some sort because there are a lot of benefits to having it backed by a normal Array

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

No branches or pull requests

2 participants