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:
		
							parent
							
								
									2d625d8c57
								
							
						
					
					
						commit
						09d31132e2
					
				|  | @ -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, | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue