@@ -209,7 +209,7 @@ impl<T> RingBuf<T> {
209
209
assert ! ( i < self . len( ) ) ;
210
210
assert ! ( j < self . len( ) ) ;
211
211
let ri = wrap_index ( self . tail + i, self . cap ) ;
212
- let rj = wrap_index ( self . tail + j, self . cap ) ;
212
+ let rj = wrap_index ( self . tail + j, self . cap ) ; ;
213
213
unsafe {
214
214
ptr:: swap ( self . ptr . offset ( ri as int ) , self . ptr . offset ( rj as int ) )
215
215
}
@@ -320,6 +320,7 @@ impl<T> RingBuf<T> {
320
320
) ;
321
321
}
322
322
self . head += oldcap;
323
+ debug_assert ! ( self . head > self . tail) ;
323
324
} else { // C
324
325
unsafe {
325
326
ptr:: copy_nonoverlapping_memory (
@@ -329,7 +330,10 @@ impl<T> RingBuf<T> {
329
330
) ;
330
331
}
331
332
self . tail = count - ( oldcap - self . tail ) ;
333
+ debug_assert ! ( self . head < self . tail) ;
332
334
}
335
+ debug_assert ! ( self . head < self . cap) ;
336
+ debug_assert ! ( self . tail < self . cap) ;
333
337
}
334
338
}
335
339
@@ -564,7 +568,10 @@ impl<T> RingBuf<T> {
564
568
/// ```
565
569
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
566
570
pub fn push_front ( & mut self , t : T ) {
567
- if self . is_full ( ) { self . reserve ( 1 ) }
571
+ if self . is_full ( ) {
572
+ self . reserve ( 1 ) ;
573
+ debug_assert ! ( !self . is_full( ) ) ;
574
+ }
568
575
569
576
self . tail = wrap_index ( self . tail - 1 , self . cap ) ;
570
577
let tail = self . tail ;
@@ -591,7 +598,10 @@ impl<T> RingBuf<T> {
591
598
/// ```
592
599
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
593
600
pub fn push_back ( & mut self , t : T ) {
594
- if self . is_full ( ) { self . reserve ( 1 ) }
601
+ if self . is_full ( ) {
602
+ self . reserve ( 1 ) ;
603
+ debug_assert ! ( !self . is_full( ) ) ;
604
+ }
595
605
596
606
let head = self . head ;
597
607
self . head = wrap_index ( self . head + 1 , self . cap ) ;
@@ -634,7 +644,9 @@ impl<T> RingBuf<T> {
634
644
#[ inline]
635
645
fn wrap_index ( index : uint , size : uint ) -> uint {
636
646
// size is always a power of 2
637
- index & ( size - 1 )
647
+ let idx = index & ( size - 1 ) ;
648
+ debug_assert ! ( idx < size) ;
649
+ idx
638
650
}
639
651
640
652
/// Calculate the number of elements left to be read in the buffer
0 commit comments