diff --git a/src/strutil.c b/src/strutil.c index 549edf13..a7f55e05 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -1508,7 +1508,7 @@ static size_t qwertydist(size_t w, unsigned char c1, unsigned char c2) { ret += sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2))/2.5*w; - return ret > w? w: ret < 1? 1: ret; + return cliptom(ret, 1, w); } // Substitution cost considering qwerty keyboard typos and case diff --git a/src/term.c b/src/term.c index 9f833bc8..e6fcc3c8 100644 --- a/src/term.c +++ b/src/term.c @@ -375,7 +375,7 @@ static unsigned char *readbuf(const PROGRAMMER *pgm, const AVRPART *p, int argc, toread = maxsize - whence; int gap = maxsize - whence - toread; - after = gap > 16? 16: gap < 0? 0: gap; + after = cliptom(gap, 0, 16); toread += after; if(toread - before < 2) // Cannot disassemble just one byte goto nocontent; @@ -3064,7 +3064,7 @@ static void update_progress_tty(int percent, double etime, const char *hdr, int cx->term_header = mmt_strdup(hdr); } - percent = percent > 100? 100: percent < 0? 0: percent; + percent = cliptom(percent, 0, 100); if(cx->term_tty_todo) { if(!cx->term_header) @@ -3095,7 +3095,7 @@ static void update_progress_tty(int percent, double etime, const char *hdr, int static void update_progress_no_tty(int percent, double etime, const char *hdr, int finish) { setvbuf(stderr, (char *) NULL, _IONBF, 0); - percent = percent > 100? 100: percent < 0? 0: percent; + percent = cliptom(percent, 0, 100); if(hdr) { lmsg_info("%s | ", hdr); diff --git a/src/urbootautogen.c b/src/urbootautogen.c index f7ff66ff..2915f73c 100644 --- a/src/urbootautogen.c +++ b/src/urbootautogen.c @@ -425,7 +425,7 @@ static int rawuartbrr(const Avrintel *up, long f_cpu, long br, int nsamples) { static int uartbrr(const Avrintel *up, long f_cpu, long br, int nsamples) { int ret = rawuartbrr(up, f_cpu, br, nsamples), mxb = maxbrr(up); - return ret < 0? 0: ret > mxb? mxb: ret; + return cliptom(ret, 0, mxb); } // Actual baud rate given f_cpu, desired baud rated and number 8..63 of samples