Skip to content

Commit 6a9fcd0

Browse files
committed
fix: potention race on circular buffer size
Signed-off-by: Jérôme Benoit <[email protected]>
1 parent 6abbc70 commit 6a9fcd0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/circular-buffer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ export class CircularBuffer {
9494
if (this.empty()) {
9595
return []
9696
}
97-
const array: number[] = new Array<number>(this.size)
97+
const size = this.size
98+
const array: number[] = new Array<number>(size)
9899
let currentIdx = this.readIdx
99-
for (let i = 0; i < this.size; i++) {
100+
for (let i = 0; i < size; i++) {
100101
array[i] = this.items[currentIdx]
101102
currentIdx = currentIdx === this.maxArrayIdx ? 0 : currentIdx + 1
102103
}

0 commit comments

Comments
 (0)