[master] 9fd79a7cb Flexelint vmin/vmax/vlimit

Nils Goroll nils.goroll at uplex.de
Wed Nov 10 11:49:06 UTC 2021


commit 9fd79a7cb69aad1597101aca6608d8bf8c03952d
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Nov 10 12:10:10 2021 +0100

    Flexelint vmin/vmax/vlimit
    
    avoid warning 666 ("Expression with side effects passed to repeated
    parameter"): The non-type macros still trigger an warning due to the
    expression passed a second time in typeof(). Use the typed macros for
    these cases.
    
    avoid error 1058 ("Initializing a non-const reference"): Our type
    check (void)(&_va == &_vb) trips for dereferences.

diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c
index 7c0bbd49a..b301c5a2f 100644
--- a/bin/varnishd/cache/cache_shmlog.c
+++ b/bin/varnishd/cache/cache_shmlog.c
@@ -378,7 +378,7 @@ VSLbs(struct vsl_log *vsl, enum VSL_tag_e tag, const struct strands *s)
 	mlen = cache_param->vsl_reclen;
 
 	/* including NUL */
-	l = vmin(strands_len(s) + 1, mlen);
+	l = vmin_t(unsigned, strands_len(s) + 1, mlen);
 
 	assert(vsl->wlp < vsl->wle);
 
diff --git a/bin/varnishd/http2/cache_http2_send.c b/bin/varnishd/http2/cache_http2_send.c
index fcbe0153a..2b66615ca 100644
--- a/bin/varnishd/http2/cache_http2_send.c
+++ b/bin/varnishd/http2/cache_http2_send.c
@@ -272,7 +272,7 @@ h2_do_window(struct worker *wrk, struct h2_req *r2,
 			(void)h2_cond_wait(h2->winupd_cond, h2, r2);
 
 		if (h2_errcheck(r2, h2) == 0) {
-			w = vmin(h2_win_limit(r2, h2), wanted);
+			w = vmin_t(int64_t, h2_win_limit(r2, h2), wanted);
 			h2_win_charge(r2, h2, w);
 			assert (w > 0);
 		}
diff --git a/bin/varnishd/storage/stevedore_utils.c b/bin/varnishd/storage/stevedore_utils.c
index 427392873..4d8abe18a 100644
--- a/bin/varnishd/storage/stevedore_utils.c
+++ b/bin/varnishd/storage/stevedore_utils.c
@@ -157,7 +157,7 @@ STV_FileSize(int fd, const char *size, unsigned *granularity, const char *ctx)
 
 	AZ(VFIL_fsinfo(fd, &bs, &fssize, NULL));
 	/* Increase granularity if it is lower than the filesystem block size */
-	*granularity = vmax(*granularity, bs);
+	*granularity = vmax_t(unsigned, *granularity, bs);
 
 	if ((size == NULL || *size == '\0') && st.st_size != 0) {
 		/*
diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index 73a7b8717..0757276ed 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -218,7 +218,7 @@ upd_vsl_ts(const char *p)
 	if (p == NULL)
 		return;
 
-	vsl_ts = vmax(vsl_ts, strtod(p + 1, NULL));
+	vsl_ts = vmax_t(double, vsl_ts, strtod(p + 1, NULL));
 }
 
 static int v_matchproto_ (VSLQ_dispatch_f)
diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c
index 46c937471..c9d7117b3 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -173,11 +173,11 @@ update_position(void)
 		current = 0;
 		page_start = 0;
 	} else {
-		current = vlimit(current, 0, n_ptarray - 1);
+		current = vlimit_t(int, current, 0, n_ptarray - 1);
 		page_start = vmin(page_start, current);
 		if (current > page_start + (l_points - 1))
 			page_start = current - (l_points - 1);
-		page_start = vlimit(page_start, 0, n_ptarray - 1);
+		page_start = vlimit_t(int, page_start, 0, n_ptarray - 1);
 	}
 
 	if (current != old_current || page_start != old_page_start)
@@ -1065,7 +1065,7 @@ handle_help_keypress(enum kb_e kb)
 		WRONG("unhandled key binding");
 	}
 
-	help_line = vlimit(help_line, 0, bindings_help_len - l_points);
+	help_line = vlimit_t(int, help_line, 0, bindings_help_len - l_points);
 	redraw = (help_line != hl);
 }
 
diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c
index 816841f13..953975333 100644
--- a/lib/libvarnish/vte.c
+++ b/lib/libvarnish/vte.c
@@ -97,7 +97,7 @@ VCLI_VTE(struct cli *cli, struct vsb **src, int width)
 		return;
 	AN(n_col);
 
-	nsp = vlimit((width - (w_ln)) / n_col, 1, 3);
+	nsp = vlimit_t(int, (width - (w_ln)) / n_col, 1, 3);
 
 	cc = 0;
 	wc = 0;


More information about the varnish-commit mailing list