dvd-sector-copy.c: Use `bad_hi' consistently for the upper bound when done.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 19 Mar 2022 14:08:43 +0000 (14:08 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 19 Mar 2022 14:08:43 +0000 (14:08 +0000)
It's just conceivable that `good' is less than `bad_hi' at this point,
which screws everything up.  It's essential to pick a consistent upper
bound here.

dvd-sector-copy.c

index 4c19389..4543296 100644 (file)
@@ -730,16 +730,16 @@ static ssize_t find_good_sector(secaddr *pos_inout, secaddr end,
     if (n == want) good = pos;
     else bad_hi = pos + n + 1;
   }
-  recovered(bad_lo, bad_hi); *pos_inout = good;
-  if (good < r.pos + r.start || r.pos + r.end <= good)
+  recovered(bad_lo, bad_hi); *pos_inout = bad_hi;
+  if (bad_hi < r.pos + r.start || r.pos + r.end <= bad_hi)
     n = 0;
   else {
-    n = r.pos + r.end - good;
-    rearrange_sectors(&r, 0, good - r.pos, n);
+    n = r.pos + r.end - bad_hi;
+    rearrange_sectors(&r, 0, bad_hi - r.pos, n);
   }
 #ifdef DEBUG
   show_recovery_buffer_map(&r, "returning %zd good sectors at %"PRIuSEC"",
-                          n, good);
+                          n, bad_hi);
 #endif
   return (n);
 }