eric-wieser / numpy_ringbuffer

Ring-buffer implementation that thinly wraps a numpy array
https://pypi.python.org/pypi/numpy_ringbuffer/
MIT License
89 stars 16 forks source link

Negative indices in unfull buffers unsafely access memory #14

Open fpdotmonkey opened 4 years ago

fpdotmonkey commented 4 years ago

In a partly-full buffer, if you take a negative index, it will refer that index to the end of the full length of the buffer as apposed to the end of the full portion of the buffer.

from numpy_ringbuffer import RingBuffer
r = RingBuffer(10)
for i in range(5):
    r.append(i)
print(r[-1])
# 3.5097786643241087e+64