Skip to content

Commit efb60b2

Browse files
authored
Merge pull request #633 from apple/eliminate-overflows-in-Version.hashValue
Eliminate arithmetic overflows in Version.hashValue
2 parents a9ed567 + 2ad2087 commit efb60b2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Sources/PackageDescription/Version.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ extension Version: Hashable {
4949
// inspired code inside the Swift stdlib.
5050
let mul: UInt64 = 0x9ddfea08eb382d69
5151
var result: UInt64 = 0
52-
result = (result &* mul) ^ UInt64(major.hashValue)
53-
result = (result &* mul) ^ UInt64(minor.hashValue)
54-
result = (result &* mul) ^ UInt64(patch.hashValue)
55-
result = prereleaseIdentifiers.reduce(result, { ($0 &* mul) ^ UInt64($1.hashValue) })
52+
result = (result &* mul) ^ UInt64(bitPattern: Int64(major.hashValue))
53+
result = (result &* mul) ^ UInt64(bitPattern: Int64(minor.hashValue))
54+
result = (result &* mul) ^ UInt64(bitPattern: Int64(patch.hashValue))
55+
result = prereleaseIdentifiers.reduce(result, { ($0 &* mul) ^ UInt64(bitPattern: Int64($1.hashValue)) })
5656
if let build = buildMetadataIdentifier {
57-
result = (result &* mul) ^ UInt64(build.hashValue)
57+
result = (result &* mul) ^ UInt64(bitPattern: Int64(build.hashValue))
5858
}
5959
return Int(truncatingBitPattern: result)
6060
}

0 commit comments

Comments
 (0)