@@ -134,6 +134,9 @@ impl SafeRead {
134134
135135impl io:: Read for SafeRead {
136136 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
137+ if self . buffer . is_none ( ) {
138+ return Err ( io:: ErrorKind :: UnexpectedEof . into ( ) ) ;
139+ }
137140 // if buffer is empty, return WoundBlock.
138141 let buffer = self . buffer . as_mut ( ) . expect ( "buffer mut expected" ) ;
139142 if buffer. is_empty ( ) {
@@ -213,6 +216,9 @@ impl SafeWrite {
213216
214217impl io:: Write for SafeWrite {
215218 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
219+ if self . buffer . is_none ( ) {
220+ return Err ( io:: ErrorKind :: UnexpectedEof . into ( ) ) ;
221+ }
216222 // if there is too much data inside the buffer, return WoundBlock
217223 let buffer = self . buffer . as_mut ( ) . expect ( "buffer mut expected" ) ;
218224 if !matches ! ( self . status, WriteStatus :: Ok ) {
@@ -233,6 +239,9 @@ impl io::Write for SafeWrite {
233239 }
234240
235241 fn flush ( & mut self ) -> io:: Result < ( ) > {
242+ if self . buffer . is_none ( ) {
243+ return Err ( io:: ErrorKind :: UnexpectedEof . into ( ) ) ;
244+ }
236245 let buffer = self . buffer . as_mut ( ) . expect ( "buffer mut expected" ) ;
237246 if !matches ! ( self . status, WriteStatus :: Ok ) {
238247 match std:: mem:: replace ( & mut self . status , WriteStatus :: Ok ) {
0 commit comments