From 3b33f0f5616d6f0fc4aa1514a5087710a4f40c82 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 28 Aug 2025 18:59:14 +0200 Subject: [PATCH] fix: potention race on circular buffer size MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/circular-buffer.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 } -- 2.43.0