make check a bit more clear
This commit is contained in:
parent
a9ef7983a6
commit
5cb830397e
1 changed files with 3 additions and 2 deletions
|
@ -384,14 +384,15 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match r.read(&mut g.buf[g.len..]) {
|
let buf = &mut g.buf[g.len..];
|
||||||
|
match r.read(buf) {
|
||||||
Ok(0) => return Ok(g.len - start_len),
|
Ok(0) => return Ok(g.len - start_len),
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
// We can't let g.len overflow which would result in the vec shrinking when the function returns. In
|
// We can't let g.len overflow which would result in the vec shrinking when the function returns. In
|
||||||
// particular, that could break read_to_string if the shortened buffer doesn't end on a UTF-8 boundary.
|
// particular, that could break read_to_string if the shortened buffer doesn't end on a UTF-8 boundary.
|
||||||
// The minimal check would just be a checked_add, but this assert is a bit more precise and should be
|
// The minimal check would just be a checked_add, but this assert is a bit more precise and should be
|
||||||
// just about the same cost.
|
// just about the same cost.
|
||||||
assert!(n <= g.buf.len() - g.len);
|
assert!(n <= buf.len());
|
||||||
g.len += n;
|
g.len += n;
|
||||||
}
|
}
|
||||||
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
|
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue