Browse Source

Bugfix

* src/buffer.c (seek_archive): Rewrite size computation
to prevent it from reaching negative values. Based on
report by Denis Excoffier <[email protected]>.
Sergey Poznyakoff 15 years ago
parent
commit
3925776b41
1 changed files with 7 additions and 7 deletions
  1. 7 7
      src/buffer.c

+ 7 - 7
src/buffer.c

@@ -854,16 +854,16 @@ seek_archive (off_t size)
   off_t start = current_block_ordinal ();
   off_t offset;
   off_t nrec, nblk;
-  off_t skipped = (blocking_factor - (current_block - record_start));
+  off_t skipped = (blocking_factor - (current_block - record_start))
+                  * BLOCKSIZE;
 
-  size -= skipped * BLOCKSIZE;
-
-  if (size < record_size)
+  if (size <= skipped)
     return 0;
-  /* FIXME: flush? */
-
+  
   /* Compute number of records to skip */
-  nrec = size / record_size;
+  nrec = (size - skipped) / record_size;
+  if (nrec == 0)
+    return 0;
   offset = rmtlseek (archive, nrec * record_size, SEEK_CUR);
   if (offset < 0)
     return offset;