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> {
1505
1505
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1506
1506
impl < T : BufRead > BufRead for Take < T > {
1507
1507
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
+
1508
1513
let buf = self . inner . fill_buf ( ) ?;
1509
1514
let cap = cmp:: min ( buf. len ( ) as u64 , self . limit ) as usize ;
1510
1515
Ok ( & buf[ ..cap] )
@@ -1860,9 +1865,16 @@ mod tests {
1860
1865
Err ( io:: Error :: new ( io:: ErrorKind :: Other , "" ) )
1861
1866
}
1862
1867
}
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
+ }
1863
1874
1864
1875
let mut buf = [ 0 ; 1 ] ;
1865
1876
assert_eq ! ( 0 , R . take( 0 ) . read( & mut buf) . unwrap( ) ) ;
1877
+ assert_eq ! ( b"" , R . take( 0 ) . fill_buf( ) . unwrap( ) ) ;
1866
1878
}
1867
1879
1868
1880
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