]> err.no Git - varnish/commitdiff
Give VSB's the mini-obj/magic treatment and enable asserts in general.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 25 Jul 2008 14:53:08 +0000 (14:53 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 25 Jul 2008 14:53:08 +0000 (14:53 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3024 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/include/vsb.h
varnish-cache/lib/libvarnish/vsb.c

index aa1836c7127c985ffda1f62d3f8062163eae1948..64d0f8a0d1075b39964eb303415453737f3cbdcf 100644 (file)
@@ -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 */
index 8c96f1e66bacd010eba7a057d17c9ee299a4b651..f3428388d718482dd0fa1a15f3dad1f4e81bb43f 100644 (file)
 #include <string.h>
 #include <strings.h>
 
+#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) {