From dbf69b7da5e1314748dd19f128517e522a6ffe6d Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Fri, 7 Apr 2023 17:44:11 +0200 Subject: [PATCH] Patch a bug in obiseq.GetSlice Former-commit-id: ab1a49c3d9bf19585e36842ecc15fa17afbcbf57 --- pkg/obiseq/pool.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/obiseq/pool.go b/pkg/obiseq/pool.go index 0b7d1be..dcf98c1 100644 --- a/pkg/obiseq/pool.go +++ b/pkg/obiseq/pool.go @@ -36,21 +36,20 @@ func GetSlice(capacity int) []byte { } if p == nil || *p == nil || cap(*p) < capacity { - s := make([]byte, 0, capacity) - p = &s + return make([]byte, 0, capacity) } + s := *p + if cap(s) < capacity { + log.Panicln("Bizarre... j'aurai pourtant cru") + } + return s } func CopySlice(src []byte) []byte { sl := GetSlice(len(src)) - - if cap(sl) < len(src) { - log.Panicln("Bizarre... j'aurai pourtant cru") - } - sl = sl[0:len(src)] copy(sl, src)