From 34e484576562aaffea2480bc3c4ee80e415a5a26 Mon Sep 17 00:00:00 2001 From: Britton Payne Date: Tue, 5 Dec 2023 06:27:53 -0800 Subject: [PATCH] Adjust size of packing slice before allocating - 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. --- internal/pkg/table/message.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/pkg/table/message.go b/internal/pkg/table/message.go index 37bea0a5..7029efdb 100644 --- a/internal/pkg/table/message.go +++ b/internal/pkg/table/message.go @@ -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)) }