]> mj.ucw.cz Git - libucw.git/commitdiff
Grrrr. Caught nasty bbcopy() bug causing sword.c scramble large files!
authorMartin Mares <mj@ucw.cz>
Tue, 10 Feb 1998 16:17:02 +0000 (16:17 +0000)
committerMartin Mares <mj@ucw.cz>
Tue, 10 Feb 1998 16:17:02 +0000 (16:17 +0000)
lib/fastbuf.c

index e5f1a873ae4a3d36436a1c6f555bb39a2da0f528..d2e6255e1426af0c1f00989365e85c89b99749d3 100644 (file)
@@ -276,19 +276,13 @@ bgets(struct fastbuf *f, byte *b, uns l)
 void bbcopy(struct fastbuf *f, struct fastbuf *t, uns l)
 {
   uns rf = f->bstop - f->bptr;
-  uns rt = t->bufend - t->bptr;
 
   if (!l)
     return;
-  if (rf && rt)
+  if (rf)
     {
-      uns k = l;
-      if (k > rf)
-       k = rf;
-      if (k > rt)
-       k = rt;
-      memcpy(t->bptr, f->bptr, k);
-      t->bptr += k;
+      uns k = (rf <= l) ? rf : l;
+      bwrite(t, f->bptr, k);
       f->bptr += k;
       l -= k;
     }
@@ -298,6 +292,7 @@ void bbcopy(struct fastbuf *f, struct fastbuf *t, uns l)
       if ((uns) read(f->fd, t->buffer, t->buflen) != t->buflen)
        die("bbcopy: %s exhausted", f->name);
       f->fdpos += t->buflen;
+      f->bstop = f->bptr = f->buffer;
       t->bptr = t->bufend;
       l -= t->buflen;
     }