Skip to content

refactor: keep same api as v0.14.0 for SplitFirst/SplitLast#271

Merged
MarcoPolo merged 2 commits intomasterfrom
marco/more-compat
Feb 21, 2025
Merged

refactor: keep same api as v0.14.0 for SplitFirst/SplitLast#271
MarcoPolo merged 2 commits intomasterfrom
marco/more-compat

Conversation

@MarcoPolo
Copy link
Contributor

@MarcoPolo MarcoPolo commented Feb 21, 2025

Perhaps not worth breaking this function, and it saves us some pain with updating downstream deps. For example, drand would not require a backport of this change to work with multiaddr.

The risk of then calling a method on the returned nil pointer is alleviated by changing the Component methods to be pointer receiver (as before) and checking for nil pointers explicitly.

Would also remove these breaking changes:

Not worth breaking this function, and it saves us some pain with
updating downstream deps
@MarcoPolo MarcoPolo requested a review from sukunrt February 21, 2025 07:38
Copy link
Member

@sukunrt sukunrt left a comment

Choose a reason for hiding this comment

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

Just one specific comment.

return nil
}
return []Component{c}
return []Component{*c}
Copy link
Member

@sukunrt sukunrt Feb 21, 2025

Choose a reason for hiding this comment

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

should we make these slices with a higher capacity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's hard to predict how a user will use this. If they want a higher capacity they should just use the slice of Components directly

util.go Outdated
Comment on lines 85 to 86
}
return m[:len(m)-1], m[len(m)-1]
return m[:len(m)-1], &m[len(m)-1]
Copy link
Member

Choose a reason for hiding this comment

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

This looks unsafe.

last points to the last element in the slice. So appends to the first bit(the multiaddr) will modify last, right?

Copy link
Member

Choose a reason for hiding this comment

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

The same argument also applies to SplitFunc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a defensive copy

@MarcoPolo MarcoPolo merged commit 2ac523b into master Feb 21, 2025
7 checks passed
@p-shahi p-shahi mentioned this pull request Feb 26, 2025
9 tasks
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