From 3c48bafab053885754369b0590d3e67941ec9187 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Tue, 16 Jan 2024 20:51:45 +0100 Subject: [PATCH] patch a low level bug in EnsureCapacity Former-commit-id: 2d50dc6923e7cfca9b864fb885577c1d1f936fc1 --- pkg/obiseq/biosequenceslice.go | 15 +++++++++++++-- pkg/obitools/obitag/obigeomtag.go | 1 - 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/obiseq/biosequenceslice.go b/pkg/obiseq/biosequenceslice.go index f1e90b6..bb7b3cf 100644 --- a/pkg/obiseq/biosequenceslice.go +++ b/pkg/obiseq/biosequenceslice.go @@ -88,8 +88,19 @@ func (s *BioSequenceSlice) EnsureCapacity(capacity int) *BioSequenceSlice { c = 0 } - if capacity > c { - *s = slices.Grow[BioSequenceSlice](*s, capacity-c) + n := 0 + for capacity > c { + old_c := c + *s = slices.Grow(*s, capacity) + c = cap(*s) + if c < capacity { + n++ + if n < 4 { + log.Warnf("cannot allocate a Biosequence Slice of size %d (only %d from %d)", capacity, c, old_c) + } else { + log.Panicf("cannot allocate a Biosequence Slice of size %d (only %d from %d)", capacity, c, old_c) + } + } } return s diff --git a/pkg/obitools/obitag/obigeomtag.go b/pkg/obitools/obitag/obigeomtag.go index 5fec126..f75eec6 100644 --- a/pkg/obitools/obitag/obigeomtag.go +++ b/pkg/obitools/obitag/obigeomtag.go @@ -138,7 +138,6 @@ func FindGeomClosest(sequence *obiseq.BioSequence, } matches := obiseq.MakeBioSequenceSlice(len(min_idx)) - matches = matches[0:len(min_idx)] for i, j := range min_idx { matches[i] = (*references)[j] }