Skip to content

NSDateComponents.hash: Fix arithmetic overflows #1645

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

Closed
wants to merge 1 commit into from

Conversation

lorentey
Copy link
Member

@lorentey lorentey commented Aug 2, 2018

NSDateComponents.hash currently hashes 13 components, while isEqual(_:) compares 17 components. The expression that produces the hash value often traps because of arithmetic overflows.

Replace the hash implementation with one that uses Hasher, feeding it with the exact same components that are compared in equality checks.

Resolves https://bugs.swift.org/browse/SR-8441

@lorentey lorentey requested review from parkera and millenomi August 2, 2018 13:54
@lorentey
Copy link
Member Author

lorentey commented Aug 2, 2018

@swift-ci test

@lorentey lorentey force-pushed the NSDateComponents.hash branch from 6237065 to 69168c2 Compare August 2, 2018 14:24
@lorentey
Copy link
Member Author

lorentey commented Aug 2, 2018

Foundation/NSCalendar.swift:1359:24: error: binary operator '!=' cannot be applied to operands of type 'Bool' and 'Int'
09:23:38         if isLeapMonth != NSDateComponentUndefined {
09:23:38            ~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~

Oops; fixed

@lorentey
Copy link
Member Author

lorentey commented Aug 2, 2018

@swift-ci please test

@lorentey
Copy link
Member Author

lorentey commented Aug 6, 2018

Closing; please see followup PR at #1656

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.

1 participant