Skip to content

Fix for [SR-2486] Crash in NSDictionary.description with NSSet inside #644

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
Sep 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Foundation/Set.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ extension Set : _ObjectTypeBridgeable {
if let o = obj as? Element {
set.insert(o)
} else {
failedConversion = true
stop.pointee = true
// here obj must be a swift type
if let nsObject = _SwiftValue.store(obj) as? Element {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you make this an "else if" to avoid nested "if"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit--never mind, since it's being merged

set.insert(nsObject)
} else {
failedConversion = true
stop.pointee = true
}
}
}
} else if type(of: source) == _NSCFSet.self {
Expand Down
13 changes: 11 additions & 2 deletions TestFoundation/TestNSSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class TestNSSet : XCTestCase {
("test_CountedSetObjectCount", test_CountedSetObjectCount),
("test_CountedSetAddObject", test_CountedSetAddObject),
("test_CountedSetRemoveObject", test_CountedSetRemoveObject),
("test_CountedSetCopying", test_CountedSetCopying)
("test_CountedSetCopying", test_CountedSetCopying),
("test_mutablesetWithDictionary", test_mutablesetWithDictionary),
]
}

Expand Down Expand Up @@ -226,5 +227,13 @@ class TestNSSet : XCTestCase {
XCTAssertTrue(NSArray(array: setMutableCopy.allObjects).index(of: entry) != NSNotFound)
}
}


func test_mutablesetWithDictionary() {
let aSet = NSMutableSet()
let dictionary = NSMutableDictionary()
let key = NSString(string: "Hello")
aSet.add(["world": "again"])
dictionary.setObject(aSet, forKey: key)
XCTAssertNotNil(dictionary.description) //should not crash
}
}