You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/reader/parser.rs
+14-5Lines changed: 14 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -399,20 +399,29 @@ impl PullParser {
399
399
400
400
#[inline]
401
401
fnnext_pos(&mutself){
402
-
ifself.pos.len() > 1{
403
-
self.pos.remove(0);
404
-
}else{
405
-
self.pos[0] = self.lexer.position();
402
+
// unfortunately calls to next_pos will never be perfectly balanced with push_pos,
403
+
// at very least because parse errors and EOF can happen unexpectedly without a prior push.
404
+
ifself.pos.len() > 0{
405
+
ifself.pos.len() > 1{
406
+
self.pos.remove(0);
407
+
}else{
408
+
self.pos[0] = self.lexer.position();
409
+
}
406
410
}
407
411
}
408
412
409
413
#[inline]
414
+
#[track_caller]
410
415
fnpush_pos(&mutself){
411
-
debug_assert!(self.pos.len() != self.pos.capacity(),"How did you get a document that weird? Please file a bug");
416
+
debug_assert!(self.pos.len() != self.pos.capacity(),"You've found a bug in xml-rs, caused by calls to push_pos() in states that don't end up emitting events.
417
+
This case is ignored in release mode, and merely causes document positions to be out of sync.
418
+
Please file a bug and include the XML document that triggers this assert.");
412
419
413
420
// it has capacity preallocated for more than it ever needs, so this reduces code size
414
421
ifself.pos.len() != self.pos.capacity(){
415
422
self.pos.push(self.lexer.position());
423
+
}elseifself.pos.len() > 1{
424
+
self.pos.remove(0);// this mitigates the excessive push_pos() call
0 commit comments