From: Jérôme Benoit Date: Thu, 28 Aug 2025 16:59:14 +0000 (+0200) Subject: fix: potention race on circular buffer size X-Git-Tag: v5.1.7~77 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3b33f0f5616d6f0fc4aa1514a5087710a4f40c82;p=poolifier.git fix: potention race on circular buffer size Signed-off-by: Jérôme Benoit --- diff --git a/src/circular-buffer.ts b/src/circular-buffer.ts index fd343ceda..13df03c13 100644 --- a/src/circular-buffer.ts +++ b/src/circular-buffer.ts @@ -88,9 +88,10 @@ export class CircularBuffer { if (this.empty()) { return [] } - const array: number[] = new Array(this.size) + const size = this.size + const array: number[] = new Array(size) let currentIdx = this.readIdx - for (let i = 0; i < this.size; i++) { + for (let i = 0; i < size; i++) { array[i] = this.items[currentIdx] currentIdx = currentIdx === this.maxArrayIdx ? 0 : currentIdx + 1 }