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

faker: fix panic from int wraparound when Intn(math.MaxInt) #160

Closed
wants to merge 1 commit into from

Conversation

sean-
Copy link
Contributor

@sean- sean- commented Dec 28, 2023

Description

When rand.Intn()'s arg wraps to a negative number, rand.Intn() panics. When faker.IntBetween(0, math.MaxInt) is used, diff is already MaxInt, so diff+1 causes an integer wraparound and rand.Intn() panics.

Also use math.MaxInt and math.MinInt constants.

Go Version

$ go version
go version go1.21.5 darwin/arm64

Go Tests

$ go test
➜ go test
2023/12/27 16:17:12 Error while requesting https://loremflickr.com/300/200 : request failed
2023/12/27 16:17:12 Error while creating a temp file: temp file creation failed
2023/12/27 16:17:12 Error while requesting https://randomuser.me : request failed
2023/12/27 16:17:12 Error while creating a temp file: temp file creation failed
PASS
ok  	github.com/jaswdr/faker	4.731s

Copy link
Owner

@jaswdr jaswdr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR, I did 2 comments of minor changes, can you take a look? The rest LGTM, I'm happy to merge it once those are fixed.

diff = 0
}

var rndInt int
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: can you rename the rndInt to just value, following the standard of the rest of the methods.

@jaswdr jaswdr mentioned this pull request Jan 20, 2024
@jaswdr
Copy link
Owner

jaswdr commented Jan 20, 2024

@sean- I took hover your PR and merged it in #163 applying the fixes to the comments I made. Thank you again for pointing this out, and congratulations for your first PR 🎉

@jaswdr jaswdr closed this Jan 20, 2024
@sean- sean- deleted the fix-intn-panic branch February 7, 2024 23:51
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.

None yet

2 participants