Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Fix bug where NilChance(0) could still result in nil #47

Merged
merged 2 commits into from
Aug 4, 2020
Merged

Fix bug where NilChance(0) could still result in nil #47

merged 2 commits into from
Aug 4, 2020

Conversation

ericcornelissen
Copy link
Contributor

Closes #46.

As discussed there, using NilChance(0) to prevent gofuzz from giving nils contained a very minor bug where it might still give nil because a randomly sampled 0 is not greater than the configured 0. This has been fixed by using >= instead of > when comparing the configured nilChance against randomly sampled values.

I also added a test case where a seeded RNG is used which will give 0 as it's first value in order to verify the bug is not reintroduced. Let me know if I should change anything about the test (or feel free to commit those changes yourself 🙂).

Because rand.Float64 can return 0 it was possible for this function to 
return false when the nilChance is set to 0 (because 0 > 0 = false).
@google-cla google-cla bot added the cla: yes label Aug 4, 2020
@ericcornelissen ericcornelissen changed the title Fix bug where NilChance(0) could still result in 0 Fix bug where NilChance(0) could still result in nil Aug 4, 2020
@lavalamp
Copy link
Contributor

lavalamp commented Aug 4, 2020

LGTM, thanks!

@lavalamp lavalamp merged commit 379e164 into google:master Aug 4, 2020
@ericcornelissen ericcornelissen deleted the fix/nil-chance-zero-if-rand-returns-0 branch August 5, 2020 06:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

go-fuzz integration may give nil values despite NilChance(0)
2 participants