r3685 - in branches/2.0/varnish-cache: bin/varnishd lib/libvarnish

tfheen at projects.linpro.no tfheen at projects.linpro.no
Fri Feb 6 15:54:28 CET 2009


Author: tfheen
Date: 2009-02-06 15:54:27 +0100 (Fri, 06 Feb 2009)
New Revision: 3685

Modified:
   branches/2.0/varnish-cache/bin/varnishd/flint.lnt
   branches/2.0/varnish-cache/lib/libvarnish/vsb.c
Log:
Merge r3496: Make vsb_new() a tad easier for FlexeLint to figure out.

Give it proper semantics



Modified: branches/2.0/varnish-cache/bin/varnishd/flint.lnt
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/flint.lnt	2009-02-06 14:50:45 UTC (rev 3684)
+++ branches/2.0/varnish-cache/bin/varnishd/flint.lnt	2009-02-06 14:54:27 UTC (rev 3685)
@@ -56,13 +56,12 @@
 -emacro(702, WEXITSTATUS)	// signed shift right 
 -efunc(525, VCC_Return_Name)	// Negative indent
 
-
 // -header(../../config.h)
 
 // Fix strchr() semtics, it can only return NULL if arg2 != 0
 -sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 ))
 
--sem(vsb_new, @p == malloc(1))
+-sem(vsb_new, @p == (1p ? 1p : malloc(1)))
 -sem(vsb_delete, custodial(1))
 -sem(lbv_assert, r_no)
 -sem(lbv_xxxassert, r_no)

Modified: branches/2.0/varnish-cache/lib/libvarnish/vsb.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvarnish/vsb.c	2009-02-06 14:50:45 UTC (rev 3684)
+++ branches/2.0/varnish-cache/lib/libvarnish/vsb.c	2009-02-06 14:54:27 UTC (rev 3685)
@@ -162,15 +162,17 @@
 		s = (struct vsb *)SBMALLOC(sizeof *s);
 		if (s == NULL)
 			return (NULL);
-		memset(s, 0, sizeof *s);
-		s->s_flags = flags;
-		s->s_magic = VSB_MAGIC;
+		if (vsb_new(s, buf, length, flags) == NULL) {
+			free(s);
+			return (NULL);
+		}
 		VSB_SETFLAG(s, VSB_DYNSTRUCT);
-	} else {
-		memset(s, 0, sizeof *s);
-		s->s_flags = flags;
-		s->s_magic = VSB_MAGIC;
+		return (s);
 	}
+
+	memset(s, 0, sizeof *s);
+	s->s_flags = flags;
+	s->s_magic = VSB_MAGIC;
 	s->s_size = length;
 	if (buf) {
 		s->s_buf = buf;
@@ -179,11 +181,8 @@
 	if (flags & VSB_AUTOEXTEND)
 		s->s_size = vsb_extendsize(s->s_size);
 	s->s_buf = (char *)SBMALLOC(s->s_size);
-	if (s->s_buf == NULL) {
-		if (VSB_ISDYNSTRUCT(s))
-			SBFREE(s);
+	if (s->s_buf == NULL)
 		return (NULL);
-	}
 	VSB_SETFLAG(s, VSB_DYNAMIC);
 	return (s);
 }



More information about the varnish-commit mailing list