Fix index-oob panic in Take::bytes (#138)

The panic happens when `inner.bytes()` returns a slice smaller than the
limit.
This commit is contained in:
Dan Burkert
2017-06-27 11:23:29 -07:00
committed by Carl Lerche
parent aab71ef82c
commit 7ed78cef47
2 changed files with 15 additions and 1 deletions
+2 -1
View File
@@ -143,7 +143,8 @@ impl<T: Buf> Buf for Take<T> {
}
fn bytes(&self) -> &[u8] {
&self.inner.bytes()[..self.limit]
let bytes = self.inner.bytes();
&bytes[..cmp::min(bytes.len(), self.limit)]
}
fn advance(&mut self, cnt: usize) {