Kaynağa Gözat

Panic on an attempt of subtracting sequence numbers with underflow.

This would result in results near usize::MAX, and is indicative of
a bug. A panic is always used instead of a debug_assert!() because
debug builds are easily slow enough so that the underlying bugs
are not tripped.

Related to #62.
whitequark 7 yıl önce
ebeveyn
işleme
d1e229261f
1 değiştirilmiş dosya ile 5 ekleme ve 1 silme
  1. 5 1
      src/wire/tcp.rs

+ 5 - 1
src/wire/tcp.rs

@@ -51,7 +51,11 @@ impl ops::Sub for SeqNumber {
     type Output = usize;
 
     fn sub(self, rhs: SeqNumber) -> usize {
-        self.0.wrapping_sub(rhs.0) as usize
+        let result = self.0.wrapping_sub(rhs.0);
+        if result < 0 {
+            panic!("attempt to subtract sequence numbers with underflow")
+        }
+        result as usize
     }
 }