[master] 23de6b115 Monday morning flexeLinting

Poul-Henning Kamp phk at FreeBSD.org
Mon Nov 11 08:49:06 UTC 2019


commit 23de6b115533d205ccb53bb08a7d24e6b044cb77
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Nov 11 08:48:03 2019 +0000

    Monday morning flexeLinting

diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index 9e86c9b62..73430d76e 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -384,7 +384,7 @@ vca_make_session(struct worker *wrk, void *arg)
 	wa->acceptsock = -1;
 	sp->listen_sock = wa->acceptlsock;
 
-	assert(wa->acceptaddrlen <= vsa_suckaddr_len);
+	assert((size_t)wa->acceptaddrlen <= vsa_suckaddr_len);
 
 	if (wa->acceptlsock->uds)
 		vca_mk_uds(wa, sp, laddr, lport, raddr, rport);
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 8796e2adf..9bffb8855 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -578,7 +578,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
 static void
 hsh_rush1(const struct worker *wrk, struct objhead *oh, struct rush *r, int max)
 {
-	unsigned u;
+	int i;
 	struct req *req;
 
 	if (max == 0)
@@ -592,7 +592,7 @@ hsh_rush1(const struct worker *wrk, struct objhead *oh, struct rush *r, int max)
 	CHECK_OBJ_NOTNULL(r, RUSH_MAGIC);
 	VTAILQ_INIT(&r->reqs);
 	Lck_AssertHeld(&oh->mtx);
-	for (u = 0; u < max; u++) {
+	for (i = 0; i < max; i++) {
 		req = VTAILQ_FIRST(&oh->waitinglist);
 		if (req == NULL)
 			break;
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 647b43665..c94ad1f11 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -151,12 +151,16 @@ SES_Set_String_Attr(struct sess *sp, enum sess_attr a, const char *src)
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	AN(src);
 
+	/*lint -save -e568 -e685 */
+
 	switch (a) {
 #define SESS_ATTR(UP, low, typ, len)	case SA_##UP: assert(len < 0); break;
 #include "tbl/sess_attr.h"
 	default:  WRONG("wrong sess_attr");
 	}
 
+	/*lint -restore */
+
 	ses_reserve_attr(sp, a, &q, strlen(src) + 1);
 	strcpy(q, src);
 }
@@ -168,12 +172,16 @@ SES_Get_String_Attr(const struct sess *sp, enum sess_attr a)
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 
+	/*lint -save -e568 -e685 */
+
 	switch (a) {
 #define SESS_ATTR(UP, low, typ, len)	case SA_##UP: assert(len < 0); break;
 #include "tbl/sess_attr.h"
 	default:  WRONG("wrong sess_attr");
 	}
 
+	/*lint -restore */
+
 	if (ses_get_attr(sp, a, &q) < 0)
 		return (NULL);
 	return (q);
diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index fcd914ba4..9f1796092 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -188,9 +188,8 @@ http1_minimal_response(struct req *req, uint16_t status)
 
 	reason = http_Status2Reason(status, NULL);
 
-	l = snprintf(buf, sizeof(buf),
-	    "HTTP/1.1 %03d %s\r\n\r\n", status, reason);
-	assert (l < sizeof(buf));
+	bprintf(buf, "HTTP/1.1 %03d %s\r\n\r\n", status, reason);
+	l = strlen(buf);
 
 	VSLb(req->vsl, SLT_RespProtocol, "HTTP/1.1");
 	VSLb(req->vsl, SLT_RespStatus, "%03d", status);
diff --git a/bin/varnishd/http2/cache_http2_session.c b/bin/varnishd/http2/cache_http2_session.c
index 8eb5c0506..aa91bc15d 100644
--- a/bin/varnishd/http2/cache_http2_session.c
+++ b/bin/varnishd/http2/cache_http2_session.c
@@ -163,7 +163,7 @@ h2_del_sess(struct worker *wrk, struct h2_sess *h2, enum sess_close reason)
 enum htc_status_e v_matchproto_(htc_complete_f)
 H2_prism_complete(struct http_conn *htc)
 {
-	int l;
+	ptrdiff_t l;
 
 	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
 	l = htc->rxbuf_e - htc->rxbuf_b;
diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c
index 5ab6db68c..4abcfe8a6 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -245,16 +245,16 @@ mgt_cli_stop_child(void)
 static void
 mgt_cli_challenge(struct cli *cli)
 {
-	int i;
+	size_t z;
 	uint8_t u;
 
 	AZ(VRND_RandomCrypto(cli->challenge, sizeof cli->challenge - 2));
-	for (i = 0; i < (sizeof cli->challenge) - 2; i++) {
+	for (z = 0; z < (sizeof cli->challenge) - 2; z++) {
 		AZ(VRND_RandomCrypto(&u, sizeof u));
-		cli->challenge[i] = (u % 26) + 'a';
+		cli->challenge[z] = (u % 26) + 'a';
 	}
-	cli->challenge[i++] = '\n';
-	cli->challenge[i] = '\0';
+	cli->challenge[z++] = '\n';
+	cli->challenge[z] = '\0';
 	VCLI_Out(cli, "%s", cli->challenge);
 	VCLI_Out(cli, "\nAuthentication required.\n");
 	VCLI_SetResult(cli, CLIS_AUTH);
@@ -691,11 +691,12 @@ mgt_DumpRstCli(void)
 {
 	const struct cli_cmd_desc *cp;
 	const char *p;
-	int i, j;
+	int z;
+	size_t j;
 
 	qsort(cmds, ncmds, sizeof cmds[0], cli_cmp);
-	for (i = 0; i < ncmds; i++, cp++) {
-		cp = cmds[i];
+	for (z = 0; z < ncmds; z++, cp++) {
+		cp = cmds[z];
 		if (!strncmp(cp->request, "debug.", 6))
 			continue;
 		printf(".. _ref_cli_");
diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index 67bacd946..93afb9d35 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -565,7 +565,7 @@ MCF_AddParams(struct parspec *ps)
 			exit(4);
 		}
 		mcf_addpar(pp);
-		if (strlen(pp->name) + 1 > margin2)
+		if (strlen(pp->name) + 1L > margin2)
 			margin2 = strlen(pp->name) + 1;
 	}
 }
@@ -733,7 +733,7 @@ MCF_DumpRstParam(void)
 	struct plist *pl;
 	const struct parspec *pp;
 	const char *p, *q, *t1, *t2;
-	int j;
+	size_t z;
 
 	printf("\n.. The following is the autogenerated "
 	    "output from varnishd -x parameter\n\n");
@@ -741,7 +741,7 @@ MCF_DumpRstParam(void)
 		pp = pl->spec;
 		printf(".. _ref_param_%s:\n\n", pp->name);
 		printf("%s\n", pp->name);
-		for (j = 0; j < strlen(pp->name); j++)
+		for (z = 0; z < strlen(pp->name); z++)
 			printf("~");
 		printf("\n");
 
diff --git a/bin/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c
index bb142f568..20a626d40 100644
--- a/bin/varnishd/proxy/cache_proxy_proto.c
+++ b/bin/varnishd/proxy/cache_proxy_proto.c
@@ -472,7 +472,8 @@ vpx_proto2(const struct worker *wrk, struct req *req)
 static enum htc_status_e v_matchproto_(htc_complete_f)
 vpx_complete(struct http_conn *htc)
 {
-	int i, l, j;
+	size_t z, l;
+	unsigned j;
 	char *p, *q;
 
 	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
@@ -483,26 +484,26 @@ vpx_complete(struct http_conn *htc)
 	l = htc->rxbuf_e - htc->rxbuf_b;
 	p = htc->rxbuf_b;
 	j = 0x3;
-	for (i = 0; i < l; i++) {
-		if (i < sizeof vpx1_sig && p[i] != vpx1_sig[i])
+	for (z = 0; z < l; z++) {
+		if (z < sizeof vpx1_sig && p[z] != vpx1_sig[z])
 			j &= ~1;
-		if (i < sizeof vpx2_sig && p[i] != vpx2_sig[i])
+		if (z < sizeof vpx2_sig && p[z] != vpx2_sig[z])
 			j &= ~2;
 		if (j == 0)
 			return (HTC_S_JUNK);
-		if (j == 1 && i == sizeof vpx1_sig) {
-			q = memchr(p + i, '\n', htc->rxbuf_e - (p + i));
+		if (j == 1 && z == sizeof vpx1_sig) {
+			q = memchr(p + z, '\n', htc->rxbuf_e - (p + z));
 			if (q != NULL && (q - htc->rxbuf_b) > 107)
 				return (HTC_S_OVERFLOW);
 			if (q == NULL)
 				return (HTC_S_MORE);
 			return (HTC_S_COMPLETE);
 		}
-		if (j == 2 && i == sizeof vpx2_sig) {
+		if (j == 2 && z == sizeof vpx2_sig) {
 			if (l < 16)
 				return (HTC_S_MORE);
 			j = vbe16dec(p + 14);
-			if (l < 16 + j)
+			if (l < 16L + j)
 				return (HTC_S_MORE);
 			return (HTC_S_COMPLETE);
 		}
diff --git a/bin/varnishd/waiter/cache_waiter_poll.c b/bin/varnishd/waiter/cache_waiter_poll.c
index 1736ba300..57f7bbcd2 100644
--- a/bin/varnishd/waiter/cache_waiter_poll.c
+++ b/bin/varnishd/waiter/cache_waiter_poll.c
@@ -118,7 +118,6 @@ vwp_del(struct vwp *vwp, int n)
 		vwp->pollfd[n] = vwp->pollfd[vwp->hpoll];
 		vwp->idx[n] = vwp->idx[vwp->hpoll];
 	}
-VSL(SLT_Debug, vwp->pollfd[vwp->hpoll].fd, "DEL");
 	memset(&vwp->pollfd[vwp->hpoll], 0, sizeof(*vwp->pollfd));
 	vwp->pollfd[vwp->hpoll].fd = -1;
 	vwp->idx[vwp->hpoll] = NULL;
@@ -154,12 +153,12 @@ vwp_dopipe(struct vwp *vwp)
 static void *
 vwp_main(void *priv)
 {
-	int v;
+	int t, v;
 	struct vwp *vwp;
 	struct waiter *w;
 	struct waited *wp;
 	double now, then;
-	int i;
+	size_t z;
 
 	THR_SetName("cache-poll");
 	THR_Init();
@@ -169,38 +168,38 @@ vwp_main(void *priv)
 	while (1) {
 		then = Wait_HeapDue(w, &wp);
 		if (wp == NULL)
-			i = -1;
+			t = -1;
 		else
-			i = (int)floor(1e3 * (then - VTIM_real()));
+			t = (int)floor(1e3 * (then - VTIM_real()));
 		assert(vwp->hpoll > 0);
 		AN(vwp->pollfd);
-		v = poll(vwp->pollfd, vwp->hpoll, i);
+		v = poll(vwp->pollfd, vwp->hpoll, t);
 		assert(v >= 0);
 		now = VTIM_real();
 		if (vwp->pollfd[0].revents)
 			v--;
-		for (i = 1; i < vwp->hpoll;) {
-			assert(vwp->pollfd[i].fd != vwp->pipes[0]);
-			wp = vwp->idx[i];
+		for (z = 1; z < vwp->hpoll;) {
+			assert(vwp->pollfd[z].fd != vwp->pipes[0]);
+			wp = vwp->idx[z];
 			CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
 
 			if (v == 0 && Wait_HeapDue(w, NULL) > now)
 				break;
-			if (vwp->pollfd[i].revents)
+			if (vwp->pollfd[z].revents)
 				v--;
 			then = Wait_When(wp);
 			if (then <= now) {
 				AN(Wait_HeapDelete(w, wp));
 				Wait_Call(w, wp, WAITER_TIMEOUT, now);
-				vwp_del(vwp, i);
-			} else if (vwp->pollfd[i].revents & POLLIN) {
+				vwp_del(vwp, z);
+			} else if (vwp->pollfd[z].revents & POLLIN) {
 				assert(wp->fd > 0);
-				assert(wp->fd == vwp->pollfd[i].fd);
+				assert(wp->fd == vwp->pollfd[z].fd);
 				AN(Wait_HeapDelete(w, wp));
 				Wait_Call(w, wp, WAITER_ACTION, now);
-				vwp_del(vwp, i);
+				vwp_del(vwp, z);
 			} else {
-				i++;
+				z++;
 			}
 		}
 		if (vwp->pollfd[0].revents)
diff --git a/include/vrt.h b/include/vrt.h
index c78f2c402..ad1d78d51 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -52,6 +52,7 @@
  * binary/load-time compatible, increment MAJOR version
  *
  * unreleased (planned for 2020-03-15)
+ *	Changed type of vsa_suckaddr_len from int to size_t
  *	New prefix_{ptr|len} fields in vrt_backend
  *	VRT_HashStrands32() added
  * 10.0 (2019-09-15)
diff --git a/include/vsa.h b/include/vsa.h
index 67c3e6266..2e4f0da91 100644
--- a/include/vsa.h
+++ b/include/vsa.h
@@ -31,7 +31,7 @@
 #define VSA_H_INCLUDED
 
 struct suckaddr;
-extern const int vsa_suckaddr_len;
+extern const size_t vsa_suckaddr_len;
 extern const struct suckaddr *bogo_ip;
 
 void VSA_Init(void);
diff --git a/lib/libvarnish/vsa.c b/lib/libvarnish/vsa.c
index 836747eac..438126ccc 100644
--- a/lib/libvarnish/vsa.c
+++ b/lib/libvarnish/vsa.c
@@ -173,7 +173,7 @@ struct suckaddr {
 	};
 };
 
-const int vsa_suckaddr_len = sizeof(struct suckaddr);
+const size_t vsa_suckaddr_len = sizeof(struct suckaddr);
 
 /*
  * Bogus IPv4 address 0.0.0.0:0 to be used for VCL *.ip variables when the


More information about the varnish-commit mailing list