From 09d31132e2d6236ae3a4d0c93f9f853a9bd1a3fe Mon Sep 17 00:00:00 2001
From: Alexandre Bury <alexandre.bury@gmail.com>
Date: Thu, 27 Oct 2016 13:02:29 -0700
Subject: [PATCH] Protects AsyncReader::read against empty buffer. (#65)

Move the check to the beginning of the loop to protect against empty buffer.
---
 src/async.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/async.rs b/src/async.rs
index a7ec8913..1db94293 100644
--- a/src/async.rs
+++ b/src/async.rs
@@ -51,14 +51,14 @@ impl Read for AsyncReader {
         let mut total = 0;
 
         loop {
+            if total >= buf.len() {
+                break;
+            }
+
             match self.recv.try_recv() {
                 Ok(Ok(b)) => {
                     buf[total] = b;
                     total += 1;
-
-                    if total == buf.len() {
-                        break;
-                    }
                 },
                 Ok(Err(e)) => return Err(e),
                 Err(_) => break,
-- 
GitLab