X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Ffb-buffer.c;h=c91dbaf4ddd425fbb5214be9c2d6094f2f0272ab;hb=97d134124cb7f43e34a976e0d6a79622c67cb455;hp=7fff1a1cfd94574bf4c1ce7f554c2cc0e827f471;hpb=681b277c0aabea785a21e109dc07338847c0cb32;p=libucw.git diff --git a/ucw/fb-buffer.c b/ucw/fb-buffer.c index 7fff1a1c..c91dbaf4 100644 --- a/ucw/fb-buffer.c +++ b/ucw/fb-buffer.c @@ -7,16 +7,18 @@ * of the GNU Lesser General Public License. */ -#include "ucw/lib.h" -#include "ucw/fastbuf.h" +#include +#include #include #include static int -fbbuf_refill(struct fastbuf *f UNUSED) +fbbuf_refill(struct fastbuf *f) { - return 0; + f->bstop = f->bufend; + f->pos = f->bstop - f->buffer; + return f->bptr < f->bstop; } static int @@ -26,10 +28,10 @@ fbbuf_seek(struct fastbuf *f, ucw_off_t pos, int whence) ucw_off_t len = f->bufend - f->buffer; if (whence == SEEK_END) pos += len; - ASSERT(pos >= 0 && pos <= len); - f->bptr = f->buffer + pos; - f->bstop = f->bufend; - f->pos = len; + if (pos < 0 || pos > len) + bthrow(f, "seek", "Seek out of range"); + f->bstop = f->bptr = f->buffer + pos; + f->pos = pos; return 1; } @@ -51,7 +53,7 @@ fbbuf_init_read(struct fastbuf *f, byte *buf, uns size, uns can_overwrite) static void fbbuf_spout(struct fastbuf *f) { - bthrow(f, "fb.write", "fbbuf: buffer overflow on write"); + bthrow(f, "write", "fbbuf: buffer overflow on write"); } void @@ -63,7 +65,6 @@ fbbuf_init_write(struct fastbuf *f, byte *buf, uns size) .bptr = buf, .bufend = buf + size, .name = "fbbuf-write", - .pos = size, .spout = fbbuf_spout, }; }