dvd-sector-copy.c: Check `n' nonnegative before comparing with unsigned.
[dvdrip] / dvd-sector-copy.c
index a2cf9c6..177ce94 100644 (file)
@@ -557,7 +557,7 @@ static ssize_t recovery_read(struct recoverybuf *r,
     } else {
       if (r->end + diff > r->sz) r->end = r->sz - diff;
       rearrange_sectors(r, r->start + diff, r->start, r->end - r->start);
-      r->start += diff; r->end += diff;
+      r->pos -= diff; r->start += diff; r->end += diff;
 #ifdef DEBUG
       show_recovery_buffer_map(r, "shifted up by %"PRIuSEC"", diff);
 #endif
@@ -577,7 +577,7 @@ static ssize_t recovery_read(struct recoverybuf *r,
     } else {
       if (r->start < diff) r->start = diff;
       rearrange_sectors(r, r->start - diff, r->start, r->end - r->start);
-      r->start -= diff; r->end -= diff;
+      r->pos += diff; r->start -= diff; r->end -= diff;
 #ifdef DEBUG
       show_recovery_buffer_map(r, "shifted down by %"PRIuSEC"", diff);
 #endif
@@ -595,7 +595,7 @@ static ssize_t recovery_read(struct recoverybuf *r,
     printf(" -> %zd\n", n);
 #endif
     if (n != nn) {
-      if (n > want) n = want;
+      if (n >= 0 && n > want) n = want;
       goto end;
     }
     r->start = pp;