Tweak to how we handle incomplete parse.

This commit is contained in:
Todd Mortimer 2021-04-06 22:41:41 -04:00
parent 9126d3c15b
commit 11adcfc97b

View file

@ -176,7 +176,15 @@ impl<'a, T: Read + Write + 'a> Handle<'a, T> {
// Update remaining data with unparsed data if needed. // Update remaining data with unparsed data if needed.
if rest.is_empty() { if rest.is_empty() {
v.clear(); v.clear();
} else if rest.len() != v.len() { } else {
// Assert on partial parse in debug builds - we expect to always parse all
// or none of the input buffer. On release builds, we still do the right thing.
debug_assert!(
rest.len() != v.len(),
"Unexpected partial parse: input: {:?}, output: {:?}",
v,
rest
);
let used = v.len() - rest.len(); let used = v.len() - rest.len();
v.drain(0..used); v.drain(0..used);
} }