diff --git a/src/parser/char_reader.rs b/src/parser/char_reader.rs index 8a74db37..9d6babf4 100644 --- a/src/parser/char_reader.rs +++ b/src/parser/char_reader.rs @@ -187,7 +187,7 @@ impl CharRead for CharReader { if self.pos >= self.buf.len() { return None; } else if self.buf.len() - self.pos >= 4 { - return match str::from_utf8(&self.buf[..e.valid_up_to()]) { + return match str::from_utf8(&self.buf[self.pos .. e.valid_up_to()]) { Ok(s) => { let mut chars = s.chars(); let c = chars.next().unwrap(); @@ -195,7 +195,7 @@ impl CharRead for CharReader { Some(Ok(c)) } Err(e) => { - let badbytes = self.buf[..e.valid_up_to()].to_vec(); + let badbytes = self.buf[self.pos .. e.valid_up_to()].to_vec(); Some(Err(io::Error::new(io::ErrorKind::InvalidData, BadUtf8Error { bytes: badbytes })))