[master] e5bf34a0c ws: Constify WS_Printf()

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Aug 31 18:41:09 UTC 2020


commit e5bf34a0c828431ae94798f572c786ff712d9f6f
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue May 5 15:33:55 2020 +0200

    ws: Constify WS_Printf()
    
    Unlike WS_Alloc() it fills the allocated space with the result, which
    should be considered constant at this point. And on top of that it's
    a constant string and shouldn't be a void pointer.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index c09b5cef6..63d72b526 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -790,7 +790,7 @@ void *WS_Alloc(struct ws *ws, unsigned bytes);
 void *WS_Copy(struct ws *ws, const void *str, int len);
 uintptr_t WS_Snapshot(struct ws *ws);
 int WS_Overflowed(const struct ws *ws);
-void *WS_Printf(struct ws *ws, const char *fmt, ...) v_printflike_(2, 3);
+const char *WS_Printf(struct ws *ws, const char *fmt, ...) v_printflike_(2, 3);
 int WS_Inside(const struct ws *, const void *, const void *);
 void WS_Assert_Allocated(const struct ws *ws, const void *ptr, ssize_t len);
 
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 9ecb5ce76..c6e8b37d7 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -282,7 +282,7 @@ http_SetH(struct http *to, unsigned n, const char *fm)
 static void
 http_PutField(struct http *to, int field, const char *string)
 {
-	char *p;
+	const char *p;
 
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
 	p = WS_Copy(to->ws, string, -1);
@@ -1182,7 +1182,7 @@ void
 http_CopyHome(const struct http *hp)
 {
 	unsigned u, l;
-	char *p;
+	const char *p;
 
 	for (u = 0; u < hp->nhd; u++) {
 		if (hp->hd[u].b == NULL) {
diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index da94c2b7d..8e2127c1f 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -224,7 +224,7 @@ WS_Copy(struct ws *ws, const void *str, int len)
 	return (r);
 }
 
-void *
+const char *
 WS_Printf(struct ws *ws, const char *fmt, ...)
 {
 	unsigned u, v;
diff --git a/include/vrt.h b/include/vrt.h
index 8a7e76e16..2177a45a7 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -56,6 +56,7 @@
  *	Added VRT_DirectorResolve()
  *	Added VCL_STRING VRT_BLOB_string(VRT_CTX, VCL_BLOB)
  *	[cache.h] WS_Reserve() removed
+ *	[cache.h] WS_Printf() changed
  * 11.0 (2020-03-16)
  *	Changed type of vsa_suckaddr_len from int to size_t
  *	New prefix_{ptr|len} fields in vrt_backend
diff --git a/lib/libvmod_cookie/vmod_cookie.c b/lib/libvmod_cookie/vmod_cookie.c
index 5be9178e6..6c8b6a3a4 100644
--- a/lib/libvmod_cookie/vmod_cookie.c
+++ b/lib/libvmod_cookie/vmod_cookie.c
@@ -58,8 +58,8 @@ static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
 struct cookie {
 	unsigned		magic;
 #define VMOD_COOKIE_ENTRY_MAGIC	0x3BB41543
-	char			*name;
-	char			*value;
+	const char		*name;
+	const char		*value;
 	VTAILQ_ENTRY(cookie)	list;
 };
 
@@ -163,7 +163,7 @@ vmod_set(VRT_CTX, struct vmod_priv *priv, VCL_STRING name, VCL_STRING value)
 {
 	struct vmod_cookie *vcp = cobj_get(priv);
 	struct cookie *cookie;
-	char *p;
+	const char *p;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);


More information about the varnish-commit mailing list