From 7a9d852a0de9e4dddfbbd6a45790821057a02705 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Thu, 23 Jun 2022 22:54:01 +0200 Subject: [PATCH] coccinelle: use macro MIN/MAX --- scripts/coccinelle/coccicheck.sh | 2 +- scripts/coccinelle/macros.cocci | 12 ++++++++++++ src/bin/termpty.c | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/scripts/coccinelle/coccicheck.sh b/scripts/coccinelle/coccicheck.sh index 4d27c422..ec39cfec 100755 --- a/scripts/coccinelle/coccicheck.sh +++ b/scripts/coccinelle/coccicheck.sh @@ -20,7 +20,7 @@ HAS_ERROR=0 for f in $COCCI_FILES; do OPTIONS="" if [ "$f" = "macros.cocci" ]; then - OPTIONS="--defined DIV_ROUND_UP --defined ROUND_UP" + OPTIONS="--defined DIV_ROUND_UP --defined ROUND_UP --defined MIN --defined MAX" fi CMD="spatch --timeout 200 --very-quiet --cocci-file scripts/coccinelle/$f --include-headers --dir $DIR $OPTIONS" OUT=$($CMD) diff --git a/scripts/coccinelle/macros.cocci b/scripts/coccinelle/macros.cocci index 62208e28..eb30304b 100644 --- a/scripts/coccinelle/macros.cocci +++ b/scripts/coccinelle/macros.cocci @@ -24,3 +24,15 @@ expression n, d; - (DIV_ROUND_UP(n,d) * d) + ROUND_UP(n, d) ) + +// MIN / MAX +@@ +expression x, y; +@@ +( +- (((x) > (y)) ? (y) : (x)) ++ MIN(x, y) +| +- (((x) > (y)) ? (x) : (y)) ++ MAX(x, y) +) diff --git a/src/bin/termpty.c b/src/bin/termpty.c index d2e41efb..178e3426 100644 --- a/src/bin/termpty.c +++ b/src/bin/termpty.c @@ -1431,8 +1431,8 @@ termpty_resize(Termpty *ty, int new_w, int new_h) free(ty->screen); ty->screen = new_screen; - ty->cursor_state.cy = (new_si.cy >= 0) ? new_si.cy : 0; - ty->cursor_state.cx = (new_si.cx >= 0) ? new_si.cx : 0; + ty->cursor_state.cy = MAX(new_si.cy, 0); + ty->cursor_state.cx = MAX(new_si.cx, 0); ty->circular_offset = new_si.circular_offset; ty->circular_offset2 = 0;