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

Add cautionary assert for divide-by-zero #622

Merged
merged 3 commits into from
Feb 14, 2019

Conversation

paulhauner
Copy link
Contributor

What

Adds a cautionary assert for divide-by-zero on get_permutated_index

Why

safety first

Adds a cautionary assert for divide-by-zero on `get_permutated_index`
@JustinDrake
Copy link
Collaborator

There is already is an implicit assert with the modulo

pivot = bytes_to_int(hash(seed + int_to_bytes1(round))[0:8]) % list_size

This produces

ZeroDivisionError: integer division or modulo by zero

@paulhauner
Copy link
Contributor Author

My objective was to make it explicit.

Maybe I've been spending too much time in a language focused on safety.

@paulhauner
Copy link
Contributor Author

Now I think about it, the spec is full of implicit asserts.

Happy to close this one.

@vbuterin
Copy link
Contributor

Technically, we really should have an assert that index < list_size, which would implicitly require list_size > 0.

@paulhauner
Copy link
Contributor Author

paulhauner commented Feb 14, 2019

Technically, we really should have an assert that index < list_size, which would implicitly require list_size > 0.

I was just about to raise this actually! It still returns a result when index >= list_size.

Edit: just updated the PR accordingly.

@JustinDrake JustinDrake self-requested a review February 14, 2019 14:14
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.

3 participants