File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -1505,6 +1505,11 @@ impl<T: Read> Read for Take<T> {
15051505#[ stable( feature = "rust1" , since = "1.0.0" ) ]
15061506impl < T : BufRead > BufRead for Take < T > {
15071507 fn fill_buf ( & mut self ) -> Result < & [ u8 ] > {
1508+ // Don't call into inner reader at all at EOF because it may still block
1509+ if self . limit == 0 {
1510+ return Ok ( & [ ] ) ;
1511+ }
1512+
15081513 let buf = self . inner . fill_buf ( ) ?;
15091514 let cap = cmp:: min ( buf. len ( ) as u64 , self . limit ) as usize ;
15101515 Ok ( & buf[ ..cap] )
@@ -1860,9 +1865,16 @@ mod tests {
18601865 Err ( io:: Error :: new ( io:: ErrorKind :: Other , "" ) )
18611866 }
18621867 }
1868+ impl BufRead for R {
1869+ fn fill_buf ( & mut self ) -> io:: Result < & [ u8 ] > {
1870+ Err ( io:: Error :: new ( io:: ErrorKind :: Other , "" ) )
1871+ }
1872+ fn consume ( & mut self , _amt : usize ) { }
1873+ }
18631874
18641875 let mut buf = [ 0 ; 1 ] ;
18651876 assert_eq ! ( 0 , R . take( 0 ) . read( & mut buf) . unwrap( ) ) ;
1877+ assert_eq ! ( b"" , R . take( 0 ) . fill_buf( ) . unwrap( ) ) ;
18661878 }
18671879
18681880 fn cmp_bufread < Br1 : BufRead , Br2 : BufRead > ( mut br1 : Br1 , mut br2 : Br2 , exp : & [ u8 ] ) {
You can’t perform that action at this time.
0 commit comments