Commit bf36c50e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Give VSB's the mini-obj/magic treatment and enable asserts in general.



git-svn-id: http://www.varnish-cache.org/svn/trunk@3024 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 7c0eeb2e
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
* Structure definition * Structure definition
*/ */
struct vsb { struct vsb {
unsigned s_magic;
char *s_buf; /* storage buffer */ char *s_buf; /* storage buffer */
void *s_unused; /* binary compatibility. */ void *s_unused; /* binary compatibility. */
int s_size; /* size of storage buffer */ int s_size; /* size of storage buffer */
......
...@@ -38,13 +38,16 @@ ...@@ -38,13 +38,16 @@
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include "libvarnish.h"
#include "vsb.h" #include "vsb.h"
#include "miniobj.h"
#define KASSERT(e, m) #define KASSERT(e, m) assert(e)
#define SBMALLOC(size) malloc(size) #define SBMALLOC(size) malloc(size)
#define SBFREE(buf) free(buf) #define SBFREE(buf) free(buf)
#define min(x,y) (x < y ? x : y) #define min(x,y) (x < y ? x : y)
#define VSB_MAGIC 0x4a82dd8a
/* /*
* Predicates * Predicates
*/ */
...@@ -77,6 +80,8 @@ _vsb_assert_integrity(const char *fun, struct vsb *s) ...@@ -77,6 +80,8 @@ _vsb_assert_integrity(const char *fun, struct vsb *s)
(void)s; (void)s;
KASSERT(s != NULL, KASSERT(s != NULL,
("%s called with a NULL vsb pointer", fun)); ("%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, KASSERT(s->s_buf != NULL,
("%s called with uninitialized or corrupt vsb", fun)); ("%s called with uninitialized or corrupt vsb", fun));
KASSERT(s->s_len < s->s_size, KASSERT(s->s_len < s->s_size,
...@@ -163,10 +168,12 @@ vsb_new(struct vsb *s, char *buf, int length, int flags) ...@@ -163,10 +168,12 @@ vsb_new(struct vsb *s, char *buf, int length, int flags)
return (NULL); return (NULL);
bzero(s, sizeof *s); bzero(s, sizeof *s);
s->s_flags = flags; s->s_flags = flags;
s->s_magic = VSB_MAGIC;
VSB_SETFLAG(s, VSB_DYNSTRUCT); VSB_SETFLAG(s, VSB_DYNSTRUCT);
} else { } else {
bzero(s, sizeof *s); bzero(s, sizeof *s);
s->s_flags = flags; s->s_flags = flags;
s->s_magic = VSB_MAGIC;
} }
s->s_size = length; s->s_size = length;
if (buf) { if (buf) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment