summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-07-31 12:21:48 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-07-31 12:21:48 +0000
commita28a432f7823cf2173d6f1e54c99438503d3174f (patch)
treec278f7343cd2cd40f3071a25c10c5da01484a0bc /src
parent3c5f5aea891c85dbdfc4d287d7ebf2bb813d6405 (diff)
downloadskalibs-a28a432f7823cf2173d6f1e54c99438503d3174f.tar.xz
Make cbuffer_?peek take a const; make *_init not leak when misused
Diffstat (limited to 'src')
-rw-r--r--src/include/skalibs/cbuffer.h4
-rw-r--r--src/libdatastruct/gensetdyn_init.c6
-rw-r--r--src/libstddjb/bufalloc_init.c3
-rw-r--r--src/libstddjb/cbuffer_rpeek.c2
-rw-r--r--src/libstddjb/cbuffer_wpeek.c2
5 files changed, 8 insertions, 9 deletions
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 <skalibs/stralloc.h>
+#include <stdint.h>
#include <skalibs/genalloc.h>
#include <skalibs/gensetdyn.h>
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 <skalibs/stralloc.h>
#include <skalibs/bufalloc.h>
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 <sys/uio.h>
#include <skalibs/cbuffer.h>
-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 <sys/uio.h>
#include <skalibs/cbuffer.h>
-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 ;