Skip to content

Commit 559d0e8

Browse files
committed
Add debug_assert! in a few places to protect invariants
1 parent c3a07b6 commit 559d0e8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/reader/buffered_reader.rs

+6
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ impl<R: BufRead> BufferedReader<R> {
458458
buf: &'buf mut Vec<u8>,
459459
position: &mut usize,
460460
) -> Result<Option<&'buf [u8]>> {
461+
// search byte must be within the ascii range
462+
debug_assert!(byte.is_ascii());
463+
461464
let mut read = 0;
462465
let mut done = false;
463466
let start = buf.len();
@@ -617,6 +620,9 @@ impl<R: BufRead> BufferedReader<R> {
617620
/// Consume and discard one character if it matches the given byte. Return
618621
/// true if it matched.
619622
fn skip_one(&mut self, byte: u8, position: &mut usize) -> Result<bool> {
623+
// search byte must be within the ascii range
624+
debug_assert!(byte.is_ascii());
625+
620626
match self.peek_one()? {
621627
Some(b) if b == byte => {
622628
*position += 1;

src/reader/slice_reader.rs

+6
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ impl<'buf> InnerReader for SliceReader<'buf> {
378378
/// Private reading functions for a [`SliceReader`].
379379
impl<'buf> SliceReader<'buf> {
380380
fn read_bytes_until(&mut self, byte: u8, position: &mut usize) -> Result<Option<&'buf [u8]>> {
381+
// search byte must be within the ascii range
382+
debug_assert!(byte.is_ascii());
383+
381384
if self.0.is_empty() {
382385
return Ok(None);
383386
}
@@ -448,6 +451,9 @@ impl<'buf> SliceReader<'buf> {
448451
}
449452

450453
fn skip_one(&mut self, byte: u8, position: &mut usize) -> Result<bool> {
454+
// search byte must be within the ascii range
455+
debug_assert!(byte.is_ascii());
456+
451457
if self.0.first() == Some(&byte) {
452458
self.0 = &self.0[1..];
453459
*position += 1;

0 commit comments

Comments
 (0)