-
Notifications
You must be signed in to change notification settings - Fork 126
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
Avoid using unsafe numeric conversions fromInteger
and fromIntegral
#637
Labels
tech-debt
For issues that require some internal refactoring.
Comments
brianhuffman
pushed a commit
that referenced
this issue
Jul 24, 2019
This was referenced May 4, 2020
We've fixed a bunch of these, but there are still some remaining. How many do we want to commit to removing before the 2.9 release? |
I think this is more aspirational and shouldn't be a requirement for the 2.9 release |
Once we add these safe numeric conversion functions, I think that will be sufficient to close this ticket. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Haskell functions
fromInteger
andfromIntegral
are used in lots of places in the cryptol codebase. These functions are likely to cause bugs due to their wrap-around behavior when converting a larger type to a smaller one, likeInteger
toInt
. (For example, see #636.)We should avoid using these functions whenever possible. (I think this would be a good rule to put in our coding style guide, once we have one. Also if we're running
hlint
along with our automated builds, we could add rules about avoidingfromIntegral
andfromInteger
.)Instead of
fromInteger
orfromIntegral
, we should either use:maybeFromInteger :: Integer -> Maybe Int
that explicitly checks for overflow, for those cases where we don't want to wrap aroundIf there are some situations where
fromInteger
orfromIntegral
really can't be avoided, we should at the very least add comments to each occurrence, explaining why it's OK in that particular situation.The text was updated successfully, but these errors were encountered: