Skip to content

Commit b198762

Browse files
committed
fix: panic_on_option_buffer
1 parent e3d9b3d commit b198762

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

monoio-rustls/src/safe_io.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ impl SafeWrite {
213213

214214
impl io::Write for SafeWrite {
215215
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
216+
if self.buffer.is_none() {
217+
return Err(io::ErrorKind::WriteZero.into());
218+
}
216219
// if there is too much data inside the buffer, return WoundBlock
217220
let buffer = self.buffer.as_mut().expect("buffer mut expected");
218221
if !matches!(self.status, WriteStatus::Ok) {
@@ -233,6 +236,9 @@ impl io::Write for SafeWrite {
233236
}
234237

235238
fn flush(&mut self) -> io::Result<()> {
239+
if self.buffer.is_none() {
240+
return Err(io::ErrorKind::WriteZero.into());
241+
}
236242
let buffer = self.buffer.as_mut().expect("buffer mut expected");
237243
if !matches!(self.status, WriteStatus::Ok) {
238244
match std::mem::replace(&mut self.status, WriteStatus::Ok) {

0 commit comments

Comments
 (0)