Skip to content

Commit

Permalink
add debug_assert in case pos > cap
Browse files Browse the repository at this point in the history
  • Loading branch information
suikammd committed Sep 22, 2021
1 parent 1ed89aa commit 67024e9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tokio/src/io/util/copy.rs
Expand Up @@ -84,6 +84,11 @@ impl CopyBuffer {
}
}

// If pos larger than cap, this loop will never stop.
// In particular, user's wrong poll_write implementation returning
// incorrect written length may lead to thread blocking.
debug_assert!(self.pos <= self.cap, "writer returned length larger than input slice");

// If we've written all the data and we've seen EOF, flush out the
// data and finish the transfer.
if self.pos == self.cap && self.read_done {
Expand Down

0 comments on commit 67024e9

Please sign in to comment.