[master] 1b2b231be take in use vlimit[_t] for existing code

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


commit 1b2b231be8109a50d97c80f318d1afcea22935fe
Author: Asad Sajjad Ahmed <asadsa at varnish-software.com>
Date:   Tue Sep 28 15:53:37 2021 +0200

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

diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index af36662cc..73a7b8717 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -300,12 +300,9 @@ accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 			continue;
 
 		/* select bucket */
-		i = lround(HIST_RES * log(value) / log_ten);
-		if (i < hist_low * HIST_RES)
-			i = hist_low * HIST_RES;
-		if (i >= hist_high * HIST_RES)
-			i = hist_high * HIST_RES - 1;
-		i -= hist_low * HIST_RES;
+		i = vlimit_t(int, lround(HIST_RES * log(value) / log_ten),
+		    hist_low * HIST_RES, hist_high * HIST_RES - 1) -
+			hist_low * HIST_RES;
 		assert(i >= 0);
 		assert((unsigned)i < hist_buckets);
 
diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c
index 91306cec2..46c937471 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -173,17 +173,11 @@ update_position(void)
 		current = 0;
 		page_start = 0;
 	} else {
-		if (current < 0)
-			current = 0;
-		if (current > n_ptarray - 1)
-			current = n_ptarray - 1;
+		current = vlimit(current, 0, n_ptarray - 1);
 		page_start = vmin(page_start, current);
 		if (current > page_start + (l_points - 1))
 			page_start = current - (l_points - 1);
-		if (page_start < 0)
-			page_start = 0;
-		if (page_start > n_ptarray - 1)
-			page_start = n_ptarray - 1;
+		page_start = vlimit(page_start, 0, n_ptarray - 1);
 	}
 
 	if (current != old_current || page_start != old_page_start)
@@ -1071,12 +1065,7 @@ handle_help_keypress(enum kb_e kb)
 		WRONG("unhandled key binding");
 	}
 
-	if (help_line > bindings_help_len - l_points)
-		help_line = bindings_help_len - l_points;
-
-	if (help_line < 0)
-		help_line = 0;
-
+	help_line = vlimit(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 69056ab5a..816841f13 100644
--- a/lib/libvarnish/vte.c
+++ b/lib/libvarnish/vte.c
@@ -97,11 +97,7 @@ VCLI_VTE(struct cli *cli, struct vsb **src, int width)
 		return;
 	AN(n_col);
 
-	nsp = (width - (w_ln)) / n_col;
-	if (nsp > 3)
-		nsp = 3;
-	else if (nsp < 1)
-		nsp = 1;
+	nsp = vlimit((width - (w_ln)) / n_col, 1, 3);
 
 	cc = 0;
 	wc = 0;


More information about the varnish-commit mailing list