r2022 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Sep 25 09:19:54 CEST 2007


Author: phk
Date: 2007-09-25 09:19:54 +0200 (Tue, 25 Sep 2007)
New Revision: 2022

Modified:
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/cache_http.c
   trunk/varnish-cache/bin/varnishd/hash_classic.c
Log:
Use pdiff() to guard against negative point differences


Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2007-09-25 07:12:18 UTC (rev 2021)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2007-09-25 07:19:54 UTC (rev 2022)
@@ -157,7 +157,7 @@
 				v = u;
 
 			/* Handle anything left in our buffer first */
-			i = bp - q;
+			i = pdiff(q, bp);
 			assert(i >= 0);
 			if (i > v)
 				i = v;
@@ -188,7 +188,7 @@
 		assert(u == 0);
 
 		/* We might still have stuff in our buffer */
-		v = bp - q;
+		v = pdiff(q, bp);
 		if (v > 0)
 			memcpy(buf, q, v);
 		q = bp = buf + v;
@@ -322,7 +322,7 @@
 	CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC);
 	/* Filter into object */
 	hp2 = &sp->obj->http;
-	len = hp->rx_e - hp->rx_s;
+	len = pdiff(hp->rx_s, hp->rx_e);
 	len += 256;		/* margin for content-length etc */
 
 	CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC);

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2007-09-25 07:12:18 UTC (rev 2021)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2007-09-25 07:19:54 UTC (rev 2022)
@@ -121,7 +121,7 @@
 		return (i);
 	b = obj->hash;
 	for (u = 0; u < sp->ihashptr; u += 2) {
-		v = sp->hashptr[u + 1] - sp->hashptr[u];
+		v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]);
 		i = memcmp(sp->hashptr[u], b, v);
 		if (i)
 			return (i);

Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2007-09-25 07:12:18 UTC (rev 2021)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2007-09-25 07:19:54 UTC (rev 2022)
@@ -289,7 +289,7 @@
 		for (q = p + 1; *q; q++)
 			if (*q == ',' || isspace(*q))
 				break;
-		i = q - p;
+		i = pdiff(p, q);
 		if (i == 5 && !strncasecmp(p, "close", i))
 			sp->doclose = "Connection: close";
 		u = http_findhdr(hp, i, p);
@@ -326,10 +326,10 @@
 		return (0);
 
 	if (len == 0)
-		len = hp->pl_e - hp->pl_s;
+		len = pdiff(hp->pl_s, hp->pl_e);
 
 	if (hp->pl_s + len > hp->pl_e)
-		len = hp->pl_e - hp->pl_s;
+		len = pdiff(hp->pl_s, hp->pl_e);
 	if (len == 0)
 		return (0);
 	*b = hp->pl_s;
@@ -351,7 +351,7 @@
 
 	u = 0;
 	if (hp->pl_s < hp->pl_e) {
-		u = hp->pl_e - hp->pl_s;
+		u = pdiff(hp->pl_s, hp->pl_e);
 		if (u > len)
 			u = len;
 		memcpy(b, hp->pl_s, u);
@@ -617,7 +617,7 @@
 	hp->rx_e = hp->rx_s;
 	if (hp->pl_s != NULL) {
 		assert(hp->pl_s < hp->pl_e);
-		l = hp->pl_e - hp->pl_s;
+		l = pdiff(hp->pl_s, hp->pl_s);
 		memmove(hp->rx_s, hp->pl_s, l);
 		hp->rx_e = hp->rx_s + l;
 		hp->pl_s = hp->pl_e = NULL;
@@ -642,7 +642,7 @@
 	unsigned l;
 	int i;
 
-	l = (hp->ws->e - hp->rx_e) - 1;
+	l = pdiff(hp->rx_e, hp->ws->e) - 1;
 	l /= 2;		/* Don't fill all of workspace with read-ahead */
 	if (l <= 1) {
 		VSL(SLT_HttpError, fd, "Received too much");
@@ -857,7 +857,7 @@
 			WSLH(w, htt, fd, hp, u);
 			continue;
 		}
-		l = hp->hd[u].e - hp->hd[u].b;
+		l = pdiff(hp->hd[u].b,  hp->hd[u].e);
 		p = WS_Alloc(hp->ws, l + 1);
 		if (p != NULL) {
 			WSLH(w, htt, fd, hp, u);

Modified: trunk/varnish-cache/bin/varnishd/hash_classic.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_classic.c	2007-09-25 07:12:18 UTC (rev 2021)
+++ trunk/varnish-cache/bin/varnishd/hash_classic.c	2007-09-25 07:19:54 UTC (rev 2022)
@@ -132,7 +132,7 @@
 
 	digest = ~0U;
 	for (u = 0; u < sp->ihashptr; u += 2) {
-		v = sp->hashptr[u + 1] - sp->hashptr[u];
+		v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]);
 		digest = crc32(digest, sp->hashptr[u], v);
 	}
 	digest ^= ~0U;




More information about the varnish-commit mailing list