[master] d5bc442 Constify txt.

Poul-Henning Kamp phk at FreeBSD.org
Sun Sep 28 19:53:46 CEST 2014


commit d5bc442e0511c19f9ce2db3301a2e66e8aa71545
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sun Sep 28 17:53:27 2014 +0000

    Constify txt.
    
    This is all Slink's fault.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index a92b011..39359b4 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -130,8 +130,8 @@ struct wrw;
 /*--------------------------------------------------------------------*/
 
 typedef struct {
-	char			*b;
-	char			*e;
+	const char		*b;
+	const char		*e;
 } txt;
 
 /*--------------------------------------------------------------------*/
@@ -867,7 +867,7 @@ void http_PutResponse(struct http *to, const char *proto, uint16_t status,
     const char *response);
 void http_FilterReq(struct http *to, const struct http *fm, unsigned how);
 void HTTP_Encode(const struct http *fm, uint8_t *, unsigned len, unsigned how);
-int HTTP_Decode(struct http *to, uint8_t *fm);
+int HTTP_Decode(struct http *to, const uint8_t *fm);
 void http_ForceHeader(struct http *to, const char *hdr, const char *val);
 void http_PrintfHeader(struct http *to, const char *fmt, ...)
     __printflike(2, 3);
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 8462ceb..d38519e 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -380,7 +380,7 @@ int
 http_GetHdr(const struct http *hp, const char *hdr, const char **ptr)
 {
 	unsigned u, l;
-	char *p;
+	const char *p;
 
 	l = hdr[0];
 	assert(l == strlen(hdr + 1));
@@ -791,7 +791,7 @@ HTTP_Encode(const struct http *fm, uint8_t *p0, unsigned l, unsigned how)
  */
 
 int
-HTTP_Decode(struct http *to, uint8_t *fm)
+HTTP_Decode(struct http *to, const uint8_t *fm)
 {
 
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
diff --git a/bin/varnishd/cache/cache_http1_proto.c b/bin/varnishd/cache/cache_http1_proto.c
index 6bfa53b..ca0a4d1 100644
--- a/bin/varnishd/cache/cache_http1_proto.c
+++ b/bin/varnishd/cache/cache_http1_proto.c
@@ -230,7 +230,7 @@ http1_dissect_hdrs(struct http *hp, char *p, const struct http_conn *htc)
 	char *q, *r;
 
 	assert(p > htc->rxbuf_b);
-	assert(p < htc->rxbuf_e);
+	assert(p <= htc->rxbuf_e);
 	hp->nhd = HTTP_HDR_FIRST;
 	hp->conds = 0;
 	r = NULL;		/* For FlexeLint */
@@ -311,6 +311,7 @@ static uint16_t
 http1_splitline(struct http *hp, const struct http_conn *htc, const int *hf)
 {
 	char *p;
+	int i;
 
 	assert(hf == HTTP1_Req || hf == HTTP1_Resp);
 	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
@@ -333,6 +334,7 @@ http1_splitline(struct http *hp, const struct http_conn *htc, const int *hf)
 	}
 	hp->hd[hf[0]].e = p;
 	assert(Tlen(hp->hd[hf[0]]));
+	*p++ = '\0';
 
 	/* Skip SP */
 	for (; vct_issp(*p); p++) {
@@ -349,6 +351,7 @@ http1_splitline(struct http *hp, const struct http_conn *htc, const int *hf)
 	hp->hd[hf[1]].e = p;
 	if (!Tlen(hp->hd[hf[1]]))
 		return (400);
+	*p++ = '\0';
 
 	/* Skip SP */
 	for (; vct_issp(*p); p++) {
@@ -367,11 +370,9 @@ http1_splitline(struct http *hp, const struct http_conn *htc, const int *hf)
 	hp->hd[hf[2]].e = p;
 
 	/* Skip CRLF */
-	p += vct_skipcrlf(p);
-
-	*hp->hd[hf[0]].e = '\0';
-	*hp->hd[hf[1]].e = '\0';
-	*hp->hd[hf[2]].e = '\0';
+	i = vct_skipcrlf(p);
+	*p = '\0';
+	p += i;
 
 	return (http1_dissect_hdrs(hp, p, htc));
 }
@@ -451,7 +452,7 @@ HTTP1_DissectRequest(struct http_conn *htc, struct http *hp)
 {
 	uint16_t retval;
 	const char *p;
-	char *b, *e;
+	const char *b, *e;
 
 	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
 	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
@@ -504,7 +505,7 @@ uint16_t
 HTTP1_DissectResponse(struct http *hp, struct http_conn *htc)
 {
 	uint16_t retval = 0;
-	char *p;
+	const char *p;
 
 
 	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
diff --git a/bin/varnishd/cache/cache_vrt_re.c b/bin/varnishd/cache/cache_vrt_re.c
index 2727ba7..822f373 100644
--- a/bin/varnishd/cache/cache_vrt_re.c
+++ b/bin/varnishd/cache/cache_vrt_re.c
@@ -39,16 +39,16 @@
 #include "vrt.h"
 
 static void
-Tadd(txt *t, const char *p, int l)
+Tadd(char **b, char *e, const char *p, int l)
 {
-	Tcheck(*t);
+	assert((*b) <= e);
 
 	if (l <= 0) {
-	} if (t->b + l < t->e) {
-		memcpy(t->b, p, l);
-		t->b += l;
+	} if ((*b) + l < e) {
+		memcpy((*b), p, l);
+		(*b) += l;
 	} else {
-		t->b = t->e;
+		(*b) = e;
 	}
 }
 
@@ -101,7 +101,8 @@ VRT_regsub(VRT_CTX, int all, const char *str, void *re,
 	int ovector[30];
 	vre_t *t;
 	int i, l;
-	txt res;
+	char *res_b;
+	char *res_e;
 	char *b0;
 	const char *s;
 	unsigned u, x;
@@ -129,27 +130,27 @@ VRT_regsub(VRT_CTX, int all, const char *str, void *re,
 	}
 
 	u = WS_Reserve(ctx->ws, 0);
-	res.e = res.b = b0 = ctx->ws->f;
-	res.e += u;
+	res_e = res_b = b0 = ctx->ws->f;
+	res_e += u;
 
 	do {
 		/* Copy prefix to match */
-		Tadd(&res, str, ovector[0]);
+		Tadd(&res_b, res_e, str, ovector[0]);
 		for (s = sub ; *s != '\0'; s++ ) {
 			if (*s != '\\' || s[1] == '\0') {
-				if (res.b < res.e)
-					*res.b++ = *s;
+				if (res_b < res_e)
+					*res_b++ = *s;
 				continue;
 			}
 			s++;
 			if (isdigit(*s)) {
 				x = *s - '0';
 				l = ovector[2*x+1] - ovector[2*x];
-				Tadd(&res, str + ovector[2*x], l);
+				Tadd(&res_b, res_e, str + ovector[2*x], l);
 				continue;
 			} else {
-				if (res.b < res.e)
-					*res.b++ = *s;
+				if (res_b < res_e)
+					*res_b++ = *s;
 			}
 		}
 		str += ovector[1];
@@ -169,12 +170,12 @@ VRT_regsub(VRT_CTX, int all, const char *str, void *re,
 	} while (i != VRE_ERROR_NOMATCH);
 
 	/* Copy suffix to match */
-	Tadd(&res, str, len+1);
-	if (res.b >= res.e) {
+	Tadd(&res_b, res_e, str, len+1);
+	if (res_b >= res_e) {
 		WS_Release(ctx->ws, 0);
 		return (str);
 	}
-	Tcheck(res);
-	WS_ReleaseP(ctx->ws, res.b);
+	assert(res_b <= res_e);
+	WS_ReleaseP(ctx->ws, res_b);
 	return (b0);
 }
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index a5aec9d..0778637 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -143,7 +143,7 @@ vmod_log(VRT_CTX, const char *fmt, ...)
 	u = WS_Reserve(ctx->ws, 0);
 	t.b = ctx->ws->f;
 	va_start(ap, fmt);
-	t.e = VRT_StringList(t.b, u, fmt, ap);
+	t.e = VRT_StringList(ctx->ws->f, u, fmt, ap);
 	va_end(ap);
 	if (t.e != NULL) {
 		assert(t.e > t.b);
@@ -164,7 +164,7 @@ vmod_syslog(VRT_CTX, VCL_INT fac, const char *fmt, ...)
 	u = WS_Reserve(ctx->ws, 0);
 	t.b = ctx->ws->f;
 	va_start(ap, fmt);
-	t.e = VRT_StringList(t.b, u, fmt, ap);
+	t.e = VRT_StringList(ctx->ws->f, u, fmt, ap);
 	va_end(ap);
 	if (t.e != NULL)
 		syslog((int)fac, "%s", t.b);



More information about the varnish-commit mailing list