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-380] Foundation hash overflows #4195

Closed
lhoward opened this issue Dec 25, 2015 · 2 comments
Closed

[SR-380] Foundation hash overflows #4195

lhoward opened this issue Dec 25, 2015 · 2 comments
Assignees

Comments

@lhoward
Copy link
Contributor

lhoward commented Dec 25, 2015

Previous ID SR-380
Radar None
Original Reporter @lhoward
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @phausler
Priority Medium

md5: b9248ab3bcd67bb0e197283e26f1749d

relates to:

  • SR-377 Implement NSKeyed[Un]Archiver

Issue Description:

I have seen this a few times. A workaround is below (commented out) but I'm not sure this is the correct approach.

@lhoward
Copy link
Contributor Author

lhoward commented Dec 30, 2015

@phausler suggested using bitPattern and this appears to fix the problem, which has also appeared in the following places (fixes below).

[rand:~/CVSRoot/apple/swift-corelibs-foundation] lukeh% git diff
diff --git a/Foundation/NSSwiftRuntime.swift b/Foundation/NSSwiftRuntime.swift
index ef1f848..d35af03 100644
--- a/Foundation/NSSwiftRuntime.swift
+++ b/Foundation/NSSwiftRuntime.swift
@@ -83,7 +83,7 @@ internal func _CFSwiftGetTypeID(cf: AnyObject) -> CFTypeID {
 
 
 internal func _CFSwiftGetHash(cf: AnyObject) -> CFHashCode {
-    return CFHashCode((cf as! NSObject).hash)
+    return CFHashCode(bitPattern: (cf as! NSObject).hash)
 }
 
 
diff --git a/Foundation/NSURL.swift b/Foundation/NSURL.swift
index 73f0bdb..9c103b0 100644
--- a/Foundation/NSURL.swift
+++ b/Foundation/NSURL.swift
@@ -60,7 +60,7 @@ public class NSURL : NSObject, NSSecureCoding, NSCopying {
     
     public override var hash: Int {
         get {
-            return Int(CFHash(_cfObject))
+            return Int(bitPattern: CFHash(_cfObject))
         }
     }

@lhoward
Copy link
Contributor Author

lhoward commented Dec 31, 2015

integrated in c120398

@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

1 participant