From: Ian Jackson Date: Sat, 17 Jul 2021 11:21:35 +0000 (+0100) Subject: zcoord: Fix some more edge case bugs in range algorithm X-Git-Tag: otter-0.7.2~55 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=6d84e4c7dda0bc89ad229de5a03b3b50e551506f;p=otter.git zcoord: Fix some more edge case bugs in range algorithm Signed-off-by: Ian Jackson --- diff --git a/base/zcoord.rs b/base/zcoord.rs index 3f494126..dcb944dc 100644 --- a/base/zcoord.rs +++ b/base/zcoord.rs @@ -382,8 +382,10 @@ impl Mutable { let mut current = a.clone(); let mut borrowing = false; let aso = 'ok: loop { for i in 0.. { - if i >= a.limbs.len() && i >= b.limbs.len() { + if i > a.limbs.len() && i > b.limbs.len() { // Oh actually these numbers are equal! + // (We have to tolerate one limb eyond each number, because possibly + // we had to borrow and add a limb to the longer number.) throw!(RangeImpossible::Empty); } //dbgc!(&a, &b, &count, i, ¤t, borrowing); @@ -392,7 +394,11 @@ impl Mutable { let la = a.limb_val_lookup(i); let lb = b.limb_val_lookup(i); - if la == lb { continue } + if la == lb && ! borrowing { + // We have not yet found any difference between these numbers + // (If we had but it wasn't enough, `borrowing` would be `true`. + continue + } let wantgaps = count+1; let avail = (lb.primitive() as i64) - (la.primitive() as i64)