From a28a432f7823cf2173d6f1e54c99438503d3174f Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 31 Jul 2017 12:21:48 +0000 Subject: Make cbuffer_?peek take a const; make *_init not leak when misused --- package/deps.mak | 4 ++-- src/include/skalibs/cbuffer.h | 4 ++-- src/libdatastruct/gensetdyn_init.c | 6 +++--- src/libstddjb/bufalloc_init.c | 3 +-- src/libstddjb/cbuffer_rpeek.c | 2 +- src/libstddjb/cbuffer_wpeek.c | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/package/deps.mak b/package/deps.mak index 3bf37f1..f89ffd9 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -117,7 +117,7 @@ src/libdatastruct/genset_iter_nocancel.o src/libdatastruct/genset_iter_nocancel. src/libdatastruct/genset_iter_withcancel.o src/libdatastruct/genset_iter_withcancel.lo: src/libdatastruct/genset_iter_withcancel.c src/include/skalibs/genset.h src/libdatastruct/gensetdyn_delete.o src/libdatastruct/gensetdyn_delete.lo: src/libdatastruct/gensetdyn_delete.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/libdatastruct/gensetdyn_free.o src/libdatastruct/gensetdyn_free.lo: src/libdatastruct/gensetdyn_free.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/include/skalibs/stralloc.h -src/libdatastruct/gensetdyn_init.o src/libdatastruct/gensetdyn_init.lo: src/libdatastruct/gensetdyn_init.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/include/skalibs/stralloc.h +src/libdatastruct/gensetdyn_init.o src/libdatastruct/gensetdyn_init.lo: src/libdatastruct/gensetdyn_init.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/libdatastruct/gensetdyn_iter.o src/libdatastruct/gensetdyn_iter.lo: src/libdatastruct/gensetdyn_iter.c src/include/skalibs/bitarray.h src/include/skalibs/gensetdyn.h src/libdatastruct/gensetdyn_iter_withcancel.o src/libdatastruct/gensetdyn_iter_withcancel.lo: src/libdatastruct/gensetdyn_iter_withcancel.c src/include/skalibs/gensetdyn.h src/libdatastruct/gensetdyn_new.o src/libdatastruct/gensetdyn_new.lo: src/libdatastruct/gensetdyn_new.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h @@ -187,7 +187,7 @@ src/libstddjb/bufalloc_clean.o src/libstddjb/bufalloc_clean.lo: src/libstddjb/bu src/libstddjb/bufalloc_flush.o src/libstddjb/bufalloc_flush.lo: src/libstddjb/bufalloc_flush.c src/include/skalibs/allreadwrite.h src/include/skalibs/bufalloc.h src/include/skalibs/functypes.h src/libstddjb/bufalloc_getfd.o src/libstddjb/bufalloc_getfd.lo: src/libstddjb/bufalloc_getfd.c src/include/skalibs/bufalloc.h src/libstddjb/bufalloc_getlen.o src/libstddjb/bufalloc_getlen.lo: src/libstddjb/bufalloc_getlen.c src/include/skalibs/bufalloc.h -src/libstddjb/bufalloc_init.o src/libstddjb/bufalloc_init.lo: src/libstddjb/bufalloc_init.c src/include/skalibs/bufalloc.h src/include/skalibs/stralloc.h +src/libstddjb/bufalloc_init.o src/libstddjb/bufalloc_init.lo: src/libstddjb/bufalloc_init.c src/include/skalibs/bufalloc.h src/libstddjb/buffer_0.o src/libstddjb/buffer_0.lo: src/libstddjb/buffer_0.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/libstddjb/buffer_0f1.o src/libstddjb/buffer_0f1.lo: src/libstddjb/buffer_0f1.c src/include/skalibs/buffer.h src/libstddjb/buffer_0small.o src/libstddjb/buffer_0small.lo: src/libstddjb/buffer_0small.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h diff --git a/src/include/skalibs/cbuffer.h b/src/include/skalibs/cbuffer.h index c29af5d..45d2e69 100644 --- a/src/include/skalibs/cbuffer.h +++ b/src/include/skalibs/cbuffer.h @@ -34,7 +34,7 @@ extern size_t cbuffer_putv (cbuffer_t *, struct iovec const *, unsigned int) ; #define cbuffer_UNPUT(b, w) ((b)->n = ((b)->a + (b)->n - w) % (b)->a, w) ; extern size_t cbuffer_unput (cbuffer_t *, size_t) ; -extern void cbuffer_wpeek (cbuffer_t *, struct iovec *) ; +extern void cbuffer_wpeek (cbuffer_t const *, struct iovec *) ; #define cbuffer_WSEEK(b, w) ((b)->n = ((b)->n + (w)) % (b)->a, w) extern size_t cbuffer_wseek (cbuffer_t *, size_t) ; @@ -46,7 +46,7 @@ extern size_t cbuffer_getv (cbuffer_t *, struct iovec const *, unsigned int) ; #define cbuffer_UNGET(b, n) ((b)->p = ((b)->a + (b)->p - n) % (b)->a, n) ; extern size_t cbuffer_unget (cbuffer_t *, size_t) ; -extern void cbuffer_rpeek (cbuffer_t *, struct iovec *) ; +extern void cbuffer_rpeek (cbuffer_t const *, struct iovec *) ; #define cbuffer_RSEEK(b, n) ((b)->p = ((b)->p + (n)) % (b)->a, n) extern size_t cbuffer_rseek (cbuffer_t *, size_t) ; diff --git a/src/libdatastruct/gensetdyn_init.c b/src/libdatastruct/gensetdyn_init.c index 744c63f..bdf4e09 100644 --- a/src/libdatastruct/gensetdyn_init.c +++ b/src/libdatastruct/gensetdyn_init.c @@ -1,13 +1,13 @@ /* ISC license. */ -#include +#include #include #include void gensetdyn_init (gensetdyn *g, uint32_t esize, uint32_t base, uint32_t fracnum, uint32_t fracden) { - g->storage = stralloc_zero ; - g->freelist = genalloc_zero ; + g->storage.len = 0 ; + genalloc_setlen(uint32_t, &g->freelist, 0) ; g->esize = esize ; g->base = base ; g->fracnum = fracnum ; diff --git a/src/libstddjb/bufalloc_init.c b/src/libstddjb/bufalloc_init.c index 6826193..0d97df9 100644 --- a/src/libstddjb/bufalloc_init.c +++ b/src/libstddjb/bufalloc_init.c @@ -1,11 +1,10 @@ /* ISC license. */ -#include #include void bufalloc_init (bufalloc *ba, ssize_t (*op)(int, char const *, size_t), int fd) { - ba->x = stralloc_zero ; + ba->x.len = 0 ; ba->op = op ; ba->fd = fd ; ba->p = 0 ; diff --git a/src/libstddjb/cbuffer_rpeek.c b/src/libstddjb/cbuffer_rpeek.c index 58cb207..8592d00 100644 --- a/src/libstddjb/cbuffer_rpeek.c +++ b/src/libstddjb/cbuffer_rpeek.c @@ -3,7 +3,7 @@ #include #include -void cbuffer_rpeek (cbuffer_t *b, struct iovec *v) +void cbuffer_rpeek (cbuffer_t const *b, struct iovec *v) { v[0].iov_base = b->x + b->p ; if (b->n >= b->p) diff --git a/src/libstddjb/cbuffer_wpeek.c b/src/libstddjb/cbuffer_wpeek.c index 8b6b586..d023294 100644 --- a/src/libstddjb/cbuffer_wpeek.c +++ b/src/libstddjb/cbuffer_wpeek.c @@ -3,7 +3,7 @@ #include #include -void cbuffer_wpeek (cbuffer_t *b, struct iovec *v) +void cbuffer_wpeek (cbuffer_t const *b, struct iovec *v) { size_t last = (b->a - 1 + b->p) % b->a ; v[0].iov_base = b->x + b->n ; -- cgit v1.2.3