Protects AsyncReader::read against empty buffer. (#65)

Move the check to the beginning of the loop to protect against empty buffer.
This commit is contained in:
Alexandre Bury 2016-10-27 13:02:29 -07:00 committed by ticki
parent 2d625d8c57
commit 09d31132e2
1 changed files with 4 additions and 4 deletions

View File

@ -51,14 +51,14 @@ impl Read for AsyncReader {
let mut total = 0; let mut total = 0;
loop { loop {
if total >= buf.len() {
break;
}
match self.recv.try_recv() { match self.recv.try_recv() {
Ok(Ok(b)) => { Ok(Ok(b)) => {
buf[total] = b; buf[total] = b;
total += 1; total += 1;
if total == buf.len() {
break;
}
}, },
Ok(Err(e)) => return Err(e), Ok(Err(e)) => return Err(e),
Err(_) => break, Err(_) => break,