Skip to content

Conversation

@cartermp
Copy link
Contributor

@cartermp cartermp commented Jan 9, 2019

Fixes #6068, where you could cause a System.OverFlowException by using a key and value that leads to calling abs on Int32.MinValue. This is invalid on .NET. The fix is to not call abs, since there's really no reason to make a hash code always positive.

Fixes #6068, where you could cause a `System.OverFlowException` by using a key and value that leads to calling `abs` on `Int32.MinValue`. This is invalid on .NET. The fix is to not call `abs`, since there's really no reason to make a hash code always positive.
member this.ComputeHashCode() =
let combineHash x y = (x <<< 1) + y + 631
let mutable res = 0
for (KeyValue(x,y)) in this do
Copy link
Contributor

Choose a reason for hiding this comment

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

The iteration here could be improved, it currently allocates. We could pass a byref through a recursive helper function, would be faster. Not critical for this PR though.

@KevinRansom KevinRansom merged commit 631401a into master Jan 12, 2019
@KevinRansom KevinRansom deleted the no-abs-map-hash branch January 31, 2019 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FSharMap.ComputeHashCode() throws OverflowException

4 participants