Skip to content

Commit

Permalink
Fix crash in NSValue.isEqual() when it is passed an NSNumber (swiftla…
Browse files Browse the repository at this point in the history
…ng#619)

NSNumbers are not added to the side table, so we can't find them.
  • Loading branch information
gribozavr authored and phausler committed Sep 4, 2016
1 parent 0dc0dac commit accc9e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Foundation/NSValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ open class NSValue : NSObject, NSCopying, NSSecureCoding, NSCoding {
} else {
// bypass _concreteValue accessor in order to avoid acquiring lock twice
let (lhs, rhs) = NSValue.SideTableLock.synchronized {
return (NSValue.SideTable[ObjectIdentifier(self)]!,
NSValue.SideTable[ObjectIdentifier(object)]!)
return (NSValue.SideTable[ObjectIdentifier(self)],
NSValue.SideTable[ObjectIdentifier(object)])
}
if let lhs = lhs, let rhs = rhs {
return lhs.isEqual(rhs)
}
return lhs.isEqual(rhs)
}
}
return false
Expand Down
8 changes: 8 additions & 0 deletions TestFoundation/TestNSValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TestNSValue : XCTestCase {
( "test_valueWithShortArray", test_valueWithShortArray ),
( "test_valueWithULongLongArray", test_valueWithULongLongArray ),
( "test_valueWithCharPtr", test_valueWithULongLongArray ),
( "test_isEqual", test_isEqual ),
]
}

Expand Down Expand Up @@ -126,4 +127,11 @@ class TestNSValue : XCTestCase {
NSValue(bytes: &charPtr, objCType: "*").getValue(&expectedPtr)
XCTAssertEqual(charPtr, expectedPtr)
}

func test_isEqual() {
let number = NSNumber(value: Int(123))
var long: Int32 = 123456
let value = NSValue(bytes: &long, objCType: "l")
XCTAssertFalse(value.isEqual(number))
}
}

0 comments on commit accc9e6

Please sign in to comment.