[master] d10a8b25e Micro polish

Nils Goroll nils.goroll at uplex.de
Mon Nov 1 10:49:06 UTC 2021


commit d10a8b25e45bf292de837d53c17908ce407f7dea
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Nov 1 11:37:57 2021 +0100

    Micro polish
    
    calling strlen() twice caused an itch

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 872f9388f..1991aea77 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -586,7 +586,7 @@ VCL_VOID
 VRT_SetHdr(VRT_CTX , VCL_HEADER hs, const char *pfx, VCL_STRANDS s)
 {
 	VCL_HTTP hp;
-	unsigned u, l;
+	unsigned u, l, pl;
 	char *p, *b;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
@@ -596,9 +596,8 @@ VRT_SetHdr(VRT_CTX , VCL_HEADER hs, const char *pfx, VCL_STRANDS s)
 	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
 
 	u = WS_ReserveAll(hp->ws);
-	l = hs->what[0] + 1;
-	if (pfx != NULL)
-		l += strlen(pfx);
+	pl = (pfx == NULL) ? 0 : strlen(pfx);
+	l = hs->what[0] + 1 + pl;
 	if (u <= l) {
 		WS_Release(hp->ws, 0);
 		WS_MarkOverflow(hp->ws);
@@ -621,11 +620,9 @@ VRT_SetHdr(VRT_CTX , VCL_HEADER hs, const char *pfx, VCL_STRANDS s)
 	memcpy(p, hs->what + 1, hs->what[0]);
 	p += hs->what[0];
 	*p++ = ' ';
-	if (pfx != NULL) {
-		l = strlen(pfx);
-		memcpy(p, pfx, l);
-		p += l;
-	}
+	if (pfx != NULL)
+		memcpy(p, pfx, pl);
+	p += pl;
 	if (FEATURE(FEATURE_VALIDATE_HEADERS) && !validhdr(b)) {
 		VRT_fail(ctx, "Bad header %s", b);
 		WS_Release(hp->ws, 0);


More information about the varnish-commit mailing list