Skip to content

Commit 33b6e6d

Browse files
committed
Add debug_assert! in a few places to protect invariants
1 parent a2298b3 commit 33b6e6d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/reader/buffered_reader.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ impl<'b, R: BufRead> XmlSource<'b, &'b mut Vec<u8>> for R {
238238
buf: &'b mut Vec<u8>,
239239
position: &mut usize,
240240
) -> Result<Option<&'b [u8]>> {
241+
// search byte must be within the ascii range
242+
debug_assert!(byte.is_ascii());
243+
241244
let mut read = 0;
242245
let mut done = false;
243246
let start = buf.len();
@@ -397,6 +400,9 @@ impl<'b, R: BufRead> XmlSource<'b, &'b mut Vec<u8>> for R {
397400
/// Consume and discard one character if it matches the given byte. Return
398401
/// true if it matched.
399402
fn skip_one(&mut self, byte: u8, position: &mut usize) -> Result<bool> {
403+
// search byte must be within the ascii range
404+
debug_assert!(byte.is_ascii());
405+
400406
match self.peek_one()? {
401407
Some(b) if b == byte => {
402408
*position += 1;

src/reader/slice_reader.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ impl<'a> XmlSource<'a, ()> for &'a [u8] {
147147
_buf: (),
148148
position: &mut usize,
149149
) -> Result<Option<&'a [u8]>> {
150+
// search byte must be within the ascii range
151+
debug_assert!(byte.is_ascii());
150152
if self.is_empty() {
151153
return Ok(None);
152154
}
@@ -217,6 +219,8 @@ impl<'a> XmlSource<'a, ()> for &'a [u8] {
217219
}
218220

219221
fn skip_one(&mut self, byte: u8, position: &mut usize) -> Result<bool> {
222+
// search byte must be within the ascii range
223+
debug_assert!(byte.is_ascii());
220224
if self.first() == Some(&byte) {
221225
*self = &self[1..];
222226
*position += 1;

0 commit comments

Comments
 (0)