Skip to content

Commit 7ec466e

Browse files
committed
fix: panic_on_option_buffer
1 parent e3d9b3d commit 7ec466e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

monoio-rustls/src/safe_io.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ impl SafeRead {
134134

135135
impl 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::Other.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

214217
impl 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::Other.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::Other.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

Comments
 (0)