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

fix: panic when Slice() accepts a negative index #256

Merged
merged 2 commits into from Nov 15, 2022

Conversation

Bin-Huang
Copy link
Contributor

@Bin-Huang Bin-Huang commented Oct 26, 2022

Previous:

lo.Slice(arr, -1, 10) // panic: runtime error: slice bounds out of range

After fixed:

lo.Slice([]int{0, 1, 2, 3}, -10, -1) // []int{}
lo.Slice([]int{0, 1, 2, 3}, -100, 2) // []int{0, 1}

I think that compared to the native method(arr[1:10]), the meaning of lo.Slice() is to avoid panic caused by out-of-bounds as much as possible. So I fixed it.

@Bin-Huang
Copy link
Contributor Author

@samber Any suggestions much appreciated

@samber
Copy link
Owner

samber commented Nov 15, 2022

Hi @Bin-Huang and sorry for the late answer.

Let's merge.

@samber samber merged commit dba7426 into samber:master Nov 15, 2022
@Bin-Huang Bin-Huang deleted the bugfix-slice-out-of-range branch November 17, 2022 03:41
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