Skip to content

Commit

Permalink
Adjust size of packing slice before allocating
Browse files Browse the repository at this point in the history
- Changes table.(*packerV4).pack.func1 (split) to adjust the max
  parameter before using it to allocate slice size.  Previously the full
  max size was allocated then max was (possibly) truncated before
  further use.
  • Loading branch information
Britton Payne authored and fujita committed Mar 2, 2024
1 parent 3448996 commit 34e4845
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/pkg/table/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,11 @@ func (p *packerV4) add(path *Path) {

func (p *packerV4) pack(options ...*bgp.MarshallingOption) []*bgp.BGPMessage {
split := func(max int, paths []*Path) ([]*bgp.IPAddrPrefix, []*Path) {
nlris := make([]*bgp.IPAddrPrefix, 0, max)
i := 0
if max > len(paths) {
max = len(paths)
}
nlris := make([]*bgp.IPAddrPrefix, 0, max)
i := 0
for ; i < max; i++ {
nlris = append(nlris, paths[i].GetNlri().(*bgp.IPAddrPrefix))
}
Expand Down

0 comments on commit 34e4845

Please sign in to comment.