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

[SR-378] NSDictionary crashes when initialising from a Swift array of objects and keys #4197

Closed
lhoward opened this issue Dec 25, 2015 · 1 comment
Assignees

Comments

@lhoward
Copy link
Contributor

lhoward commented Dec 25, 2015

Previous ID SR-378
Radar None
Original Reporter @lhoward
Type Bug
Status Closed
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @phausler
Priority Medium

md5: db29dcc26d00ab8317144fec2875893b

blocks:

  • SR-377 Implement NSKeyed[Un]Archiver

Issue Description:

NSDictionary.init(objects: [AnyObject], forKeys keys: [NSObject]) crashes because keyBuffer/valueBuffer are uninitialised and the Swift runtime attempts to release the uninitialised memory before assignment:

    public convenience init(objects: [AnyObject], forKeys keys: [NSObject]) {
        let keyBuffer = UnsafeMutablePointer<NSObject>.alloc(keys.count)
        for idx in 0..<keys.count {
            keyBuffer[idx] = keys[idx]
        }
...

I can workaround it by adding the following immediately after initialisation:

bzero(unsafeBitCast(keyBuffer, UnsafeMutablePointer<Void>.self), keys.count * sizeof(NSObject))

But this doesn't strike me as the most idiomatically Swift way to do this. Suggestions on a better fix would be welcome.

@phausler
Copy link
Member

f79b184

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants