From: phk Date: Fri, 25 Jul 2008 14:53:08 +0000 (+0000) Subject: Give VSB's the mini-obj/magic treatment and enable asserts in general. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d1087c5a7a50bf151bf1fbe8adcbaced723ee32;p=varnish Give VSB's the mini-obj/magic treatment and enable asserts in general. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3024 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/include/vsb.h b/varnish-cache/include/vsb.h index aa1836c7..64d0f8a0 100644 --- a/varnish-cache/include/vsb.h +++ b/varnish-cache/include/vsb.h @@ -36,6 +36,7 @@ * Structure definition */ struct vsb { + unsigned s_magic; char *s_buf; /* storage buffer */ void *s_unused; /* binary compatibility. */ int s_size; /* size of storage buffer */ diff --git a/varnish-cache/lib/libvarnish/vsb.c b/varnish-cache/lib/libvarnish/vsb.c index 8c96f1e6..f3428388 100644 --- a/varnish-cache/lib/libvarnish/vsb.c +++ b/varnish-cache/lib/libvarnish/vsb.c @@ -38,13 +38,16 @@ #include #include +#include "libvarnish.h" #include "vsb.h" +#include "miniobj.h" -#define KASSERT(e, m) +#define KASSERT(e, m) assert(e) #define SBMALLOC(size) malloc(size) #define SBFREE(buf) free(buf) #define min(x,y) (x < y ? x : y) +#define VSB_MAGIC 0x4a82dd8a /* * Predicates */ @@ -77,6 +80,8 @@ _vsb_assert_integrity(const char *fun, struct vsb *s) (void)s; KASSERT(s != NULL, ("%s called with a NULL vsb pointer", fun)); + KASSERT(s->s_magic == VSB_MAGIC, + ("%s called wih an unintialized vsb pointer", fun)); KASSERT(s->s_buf != NULL, ("%s called with uninitialized or corrupt vsb", fun)); KASSERT(s->s_len < s->s_size, @@ -163,10 +168,12 @@ vsb_new(struct vsb *s, char *buf, int length, int flags) return (NULL); bzero(s, sizeof *s); s->s_flags = flags; + s->s_magic = VSB_MAGIC; VSB_SETFLAG(s, VSB_DYNSTRUCT); } else { bzero(s, sizeof *s); s->s_flags = flags; + s->s_magic = VSB_MAGIC; } s->s_size = length; if (buf) {