[master] 393524d27 take in use vmax[_t] for existing code

Nils Goroll nils.goroll at uplex.de
Mon Nov 8 16:14:06 UTC 2021


commit 393524d273e618346550e1c069e56a5a6a265cb0
Author: Asad Sajjad Ahmed <asadsa at varnish-software.com>
Date:   Tue Sep 28 15:35:00 2021 +0200

    take in use vmax[_t] for existing code
    
    Signed-off-by: Asad Sajjad Ahmed <asadsa at varnish-software.com>

diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index 645bfbd04..39b2dace5 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -319,9 +319,7 @@ child_sigmagic(size_t altstksz)
 	memset(&sa, 0, sizeof sa);
 
 #ifdef HAVE_SIGALTSTACK
-	size_t sz = SIGSTKSZ + 4096;
-	if (sz < altstksz)
-		sz = altstksz;
+	size_t sz = vmax_t(size_t, SIGSTKSZ + 4096, altstksz);
 	altstack.ss_sp = mmap(NULL, sz,  PROT_READ | PROT_WRITE,
 			      MAP_PRIVATE | MAP_ANONYMOUS,
 			      -1, 0);
diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c
index f4eedc1f5..ee4159005 100644
--- a/bin/varnishd/cache/cache_req_body.c
+++ b/bin/varnishd/cache/cache_req_body.c
@@ -100,8 +100,7 @@ vrb_pull(struct req *req, ssize_t maxsize, objiterate_f *func, void *priv)
 		req->want100cont = 0;
 		(void)req->transport->minimal_response(req, 100);
 	}
-	if (yet < 0)
-		yet = 0;
+	yet = vmax_t(ssize_t, yet, 0);
 	do {
 		AZ(vfc->failed);
 		if (maxsize >= 0 && req_bodybytes > maxsize) {
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 2294e742c..c73c28385 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -1011,8 +1011,7 @@ VRT_l_sess_##x(VRT_CTX, VCL_DURATION d)		\
 {							\
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);		\
 	CHECK_OBJ_NOTNULL(ctx->sp, SESS_MAGIC);		\
-	if (d < 0.0)					\
-		d = 0.0;				\
+	d = vmax(d, 0.0);				\
 	setter;						\
 	ctx->sp->x = d;					\
 }							\
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index 3ef669de8..b44aa23bc 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -682,8 +682,9 @@ pool_herder(void *priv)
 				VSC_C_main->threads_destroyed++;
 				Lck_Unlock(&pool_mtx);
 				delay = cache_param->wthread_destroy_delay;
-			} else if (delay < cache_param->wthread_destroy_delay)
-				delay = cache_param->wthread_destroy_delay;
+			} else
+				delay = vmax(delay, 
+				    cache_param->wthread_destroy_delay);
 		}
 
 		if (pp->die) {
diff --git a/bin/varnishd/hpack/vhp_gen_hufdec.c b/bin/varnishd/hpack/vhp_gen_hufdec.c
index cf18857cc..a69d1df83 100644
--- a/bin/varnishd/hpack/vhp_gen_hufdec.c
+++ b/bin/varnishd/hpack/vhp_gen_hufdec.c
@@ -234,8 +234,7 @@ main(int argc, const char **argv)
 	(void)argv;
 
 	for (u = 0; u < HUF_LEN; u++) {
-		if (maxlen < huf[u].blen)
-			maxlen = huf[u].blen;
+		maxlen = vmax(maxlen, huf[u].blen);
 		minlen = vmin(minlen, huf[u].blen);
 	}
 
diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c
index 6488c5b03..441a12166 100644
--- a/bin/varnishd/mgt/mgt_acceptor.c
+++ b/bin/varnishd/mgt/mgt_acceptor.c
@@ -130,8 +130,7 @@ MAC_reopen_sockets(void)
 		VJ_master(JAIL_MASTER_LOW);
 		if (err == 0)
 			continue;
-		if (err > fail)
-			fail = err;
+		fail = vmax(fail, err);
 		MGT_Complain(C_ERR,
 		    "Could not reopen listen socket %s: %s",
 		    ls->endpoint, VAS_errtxt(err));
diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index 5af419fed..a8181bd56 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -204,8 +204,7 @@ MCH_TrackHighFd(int fd)
 	 * in the master process.
 	 */
 	assert(fd > 0);
-	if (fd > mgt_max_fd)
-		mgt_max_fd = fd;
+	mgt_max_fd = vmax(mgt_max_fd, fd);
 }
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index d80033269..308015ced 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -574,8 +574,7 @@ MCF_AddParams(struct parspec *ps)
 			exit(4);
 		}
 		mcf_addpar(pp);
-		if ((int)strlen(pp->name) + 1 > margin2)
-			margin2 = (int)strlen(pp->name) + 1;
+		margin2 = vmax_t(int, margin2, strlen(pp->name) + 1);
 	}
 }
 
diff --git a/bin/varnishd/storage/stevedore_utils.c b/bin/varnishd/storage/stevedore_utils.c
index ac70b7aaf..427392873 100644
--- a/bin/varnishd/storage/stevedore_utils.c
+++ b/bin/varnishd/storage/stevedore_utils.c
@@ -157,8 +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 */
-	if (*granularity < bs)
-		*granularity = bs;
+	*granularity = vmax(*granularity, bs);
 
 	if ((size == NULL || *size == '\0') && st.st_size != 0) {
 		/*
diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index 9a4d58917..af36662cc 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -174,8 +174,7 @@ update(void)
 		assert(l < n);
 		bm[l] += bucket_miss[k];
 		bh[l] += bucket_hit[k];
-		if (bm[l] + bh[l] > max)
-			max = bm[l] + bh[l];
+		max = vmax(max, bm[l] + bh[l]);
 	}
 
 	/* scale,time */
@@ -210,7 +209,6 @@ update(void)
 inline static void
 upd_vsl_ts(const char *p)
 {
-	double t;
 
 	if (timebend == 0)
 		return;
@@ -220,10 +218,7 @@ upd_vsl_ts(const char *p)
 	if (p == NULL)
 		return;
 
-	t = strtod(p + 1, NULL);
-
-	if (t > vsl_ts)
-		vsl_ts = t;
+	vsl_ts = vmax(vsl_ts, strtod(p + 1, NULL));
 }
 
 static int v_matchproto_ (VSLQ_dispatch_f)
@@ -432,9 +427,7 @@ do_curses(void *arg)
 			ms_delay = 1000U << (ch - '0');
 			break;
 		case '+':
-			ms_delay /= 2;
-			if (ms_delay < 1)
-				ms_delay = 1;
+			ms_delay = vmax(ms_delay >> 1, 1);
 			break;
 		case '-':
 			ms_delay *= 2;
diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c
index 0f9aa3652..91306cec2 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -362,8 +362,7 @@ make_windows(void)
 		l_points += l_info;
 		l_info = 0;
 	}
-	if (l_points < LINES_POINTS_MIN)
-		l_points = LINES_POINTS_MIN;
+	l_points = vmax(l_points, LINES_POINTS_MIN);
 
 	y = 0;
 	y_status = y;
diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c
index 119dd9880..69056ab5a 100644
--- a/lib/libvarnish/vte.c
+++ b/lib/libvarnish/vte.c
@@ -82,12 +82,10 @@ VCLI_VTE(struct cli *cli, struct vsb **src, int width)
 			wc = 0;
 		}
 		if (*p == '\n') {
-			if (cc > n_col)
-				n_col = cc;
+			n_col = vmax(n_col, cc);
+			w_ln = vmax(w_ln, wl);
 			cc = 0;
 			wc = 0;
-			if (wl > w_ln)
-				w_ln = wl;
 			wl = 0;
 		} else {
 			wc++;
diff --git a/vmod/vmod_directors_shard_cfg.c b/vmod/vmod_directors_shard_cfg.c
index 4c10334ae..438609063 100644
--- a/vmod/vmod_directors_shard_cfg.c
+++ b/vmod/vmod_directors_shard_cfg.c
@@ -411,8 +411,7 @@ shardcfg_backend_expand(const struct backend_reconfig *re)
 
 	CHECK_OBJ_NOTNULL(re->shardd, SHARDDIR_MAGIC);
 
-	if (min < 16)
-		min = 16;
+	min = vmax_t(unsigned, min, 16);
 
 	if (re->shardd->l_backend < min)
 		re->shardd->l_backend = min;
diff --git a/vmod/vmod_std.c b/vmod/vmod_std.c
index 719c5051a..8ce144eb9 100644
--- a/vmod/vmod_std.c
+++ b/vmod/vmod_std.c
@@ -242,8 +242,7 @@ VCL_BOOL v_matchproto_(td_std_cache_req_body)
 vmod_cache_req_body(VRT_CTX, VCL_BYTES size)
 {
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
-	if (size < 0)
-		size = 0;
+	size = vmax_t(VCL_BYTES, size, 0);
 	if (VRT_CacheReqBody(ctx, (size_t)size) < 0)
 		return (0);
 	return (1);


More information about the varnish-commit mailing list