Skip to content

Commit

Permalink
add better no op detection in char_reader.rs (#2297)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthom committed Jan 17, 2024
1 parent 29ced36 commit e3aa85e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/parser/char_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<R: Read> CharRead for CharReader<R> {
return Some(Err(bad_bytes_error(buf)));
} else if self.pos >= self.buf.len() {
return None;
} else if self.buf.len() - self.pos >= 4 {
} else if self.buf.len() - self.pos >= 4 && self.pos < e.valid_up_to() {
return match str::from_utf8(&self.buf[self.pos..e.valid_up_to()]) {
Ok(s) => {
let mut chars = s.chars();
Expand All @@ -218,6 +218,11 @@ impl<R: Read> CharRead for CharReader<R> {
self.buf.truncate(buf_len - self.pos);

let buf_len = self.buf.len();
self.pos = 0;

if buf_len >= 4 {
continue;
}

let mut word = [0u8; 4];
let word_slice = &mut word[buf_len..4];
Expand All @@ -229,8 +234,6 @@ impl<R: Read> CharRead for CharReader<R> {
self.buf.extend_from_slice(&word_slice[0..nread]);
}
}

self.pos = 0;
}
} else {
return None;
Expand Down

0 comments on commit e3aa85e

Please sign in to comment.