jeromefroe / circbuf-rs

A growable circular buffer for working with bytes
https://docs.rs/circbuf/
MIT License
18 stars 8 forks source link

write() panics if buf.len() == 0 #1

Closed abaumhauer closed 6 years ago

abaumhauer commented 6 years ago

If one attempts to write a zero sized buffer a panic occurs with 'tests::read_and_write_bytes' panicked at 'index out of bounds: the len is 0 but the index is 0'

The following patch and test corrects this issue by returning Ok(0) if the write is empty.

diff --git a/src/lib.rs b/src/lib.rs index 8d4ba40..0baa6b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -503,7 +503,7 @@ impl io::Write for CircBuf { fn write(&mut self, buf: &[u8]) -> io::Result { let avail = self.avail();

@@ -680,6 +680,7 @@ mod tests { fn read_and_write_bytes() { let mut c = CircBuf::with_capacity(8).unwrap();

jeromefroe commented 6 years ago

Thanks for the patch! I just pushed a commit to apply your fix and cut a new release, 0.1.4, with the changes.