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

Fixed division by zero #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fixed division by zero #59

wants to merge 1 commit into from

Conversation

timkoers
Copy link

@timkoers timkoers commented Nov 4, 2019

When the --single flag was used, an division by zero was generated in the munit_rand_state_at_most function.
Fixed and tested

When the --single flag was used, an division by zero was generated in the munit_rand_state_at_most function.
Fixed and tested
@jibsen
Copy link
Collaborator

jibsen commented Nov 5, 2019

I just had a quick glance at the code, and am wondering if it might be better to check if possible is 1 at https://github.com/nemequ/munit/blob/master/munit.c#L1617 instead?

My thinking is that calling munit_rand_at_most with a max of 0 is a bug, and it's better to fix that bug than to slow down the PRNG for all other uses by adding the check.

@jibsen
Copy link
Collaborator

jibsen commented Nov 5, 2019

Hmm interesting, I had a recollection of this being fixed before, and looks like the empty range in #30 was it, but firstly that is in the public API, not the internal function used here, and also the fix seems to have disappeared again?

@jibsen
Copy link
Collaborator

jibsen commented Nov 6, 2019

My thinking is that calling munit_rand_at_most with a max of 0 is a bug

Looks like my thinking was wrong, the ranges appear to be inclusive, so calling it with max equal to 0 should return 0.

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.

2 participants