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 new Concat utility and use it to fix slice.append gotcha #416

Merged
merged 6 commits into from
Aug 8, 2024

Conversation

phillip-stephens
Copy link
Contributor

@phillip-stephens phillip-stephens commented Aug 8, 2024

While debugging an issue with Phillip/ipv6, I realized that
newSlice := append(inputSlice1, inputSlice2...)
can modify inputSlice1.

While Concat was added in go 1.22, I think that's a bit too cutting edge to mandate people have.

I could not find a linter to automatically check for these sorts of issues, so we'll just have to be careful.

Changes

  • added new utility Concat copied from Go's std. lib.
  • added testing to show it doesn't modify underlying array
  • Used everywhere we were using append to create a new slice

@phillip-stephens phillip-stephens marked this pull request as ready for review August 8, 2024 16:15
@phillip-stephens phillip-stephens requested a review from a team as a code owner August 8, 2024 16:15
@phillip-stephens phillip-stephens requested a review from zakird August 8, 2024 16:15
@zakird zakird merged commit efe395f into main Aug 8, 2024
3 checks passed
@zakird zakird deleted the phillip/slice-gotcha branch August 9, 2024 00:03
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