]> Piment Noir Git Repositories - poolifier.git/commitdiff
fix: potention race on circular buffer size
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 28 Aug 2025 16:59:14 +0000 (18:59 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 28 Aug 2025 16:59:14 +0000 (18:59 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/circular-buffer.ts

index fd343ceda04e977bf7c5e0114a4b4a28760505a1..13df03c132350dff5fa6398d54cf880c7a56e061 100644 (file)
@@ -88,9 +88,10 @@ export class CircularBuffer {
     if (this.empty()) {
       return []
     }
-    const array: number[] = new Array<number>(this.size)
+    const size = this.size
+    const array: number[] = new Array<number>(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
     }