X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Ffb-mem.c;h=d5e6e8b96f4e54bfd4b70fd4d6ae02849a7e8849;hb=8ffdaed1c5f5bf4ad0914b8d17f14af51ce037a5;hp=e83e2ebc69145c8f40c36fa8865f035470c8f738;hpb=1571781022499a9d0c32d249f89945d034d1cbff;p=libucw.git diff --git a/lib/fb-mem.c b/lib/fb-mem.c index e83e2ebc..d5e6e8b9 100644 --- a/lib/fb-mem.c +++ b/lib/fb-mem.c @@ -34,7 +34,7 @@ fbmem_refill(struct fastbuf *f) if (!b) return 0; } - else if (f->bstop < b->data + b->size) + else if (f->buffer == b->data && f->bstop < b->data + b->size) { f->bstop = b->data + b->size; return 1; @@ -46,6 +46,8 @@ fbmem_refill(struct fastbuf *f) f->pos += b->size; b = b->next; } + if (!b->size) + return 0; f->buffer = f->bptr = b->data; f->bufend = f->bstop = b->data + b->size; f->llpos = b; @@ -89,7 +91,7 @@ fbmem_seek(struct fastbuf *f, sh_off_t pos, int whence) die("fbmem_seek: only SEEK_SET supported"); for (b=m->first; b; b=b->next) { - if (pos <= p + b->size) /* <=, because we need to be able to seek just after file end */ + if ((unsigned) pos <= p + b->size) /* <=, because we need to be able to seek just after file end */ { f->pos = p; f->buffer = b->data; @@ -115,28 +117,23 @@ fbmem_close(struct fastbuf *f) while (b = m->first) { m->first = b->next; - free(b); + xfree(b); } - free(m); + xfree(m); } struct fastbuf * fbmem_create(unsigned blocksize) { - struct fastbuf *f = xmalloc(sizeof(struct fastbuf)); - struct memstream *m = xmalloc(sizeof(struct memstream)); + struct fastbuf *f = xmalloc_zero(sizeof(struct fastbuf)); + struct memstream *m = xmalloc_zero(sizeof(struct memstream)); m->blocksize = blocksize; m->uc = 1; - m->first = NULL; - f->bptr = f->bstop = f->buffer = f->bufend = NULL; - f->pos = f->fdpos = 0; f->name = ""; f->lldata = m; - f->refill = NULL; f->spout = fbmem_spout; - f->seek = NULL; f->close = fbmem_close; return f; } @@ -144,17 +141,15 @@ fbmem_create(unsigned blocksize) struct fastbuf * fbmem_clone_read(struct fastbuf *b) { - struct fastbuf *f = xmalloc(sizeof(struct fastbuf)); + struct fastbuf *f = xmalloc_zero(sizeof(struct fastbuf)); struct memstream *s = b->lldata; + bflush(b); s->uc++; - f->bptr = f->bstop = f->buffer = f->bufend = NULL; - f->pos = f->fdpos = 0; f->name = ""; f->lldata = s; f->refill = fbmem_refill; - f->spout = NULL; f->seek = fbmem_seek; f->close = fbmem_close; return f;