aboutsummaryrefslogtreecommitdiff
path: root/tty.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2018-09-24 12:17:29 +0100
committerNicholas Marriott <nicholas.marriott@gmail.com>2018-09-24 12:17:29 +0100
commitad71e7f9d247e4745cf80c7ec6f698e959adb99f (patch)
tree31b10f94492592f36257ff4e1dfb800d05fbf0a5 /tty.c
parent71d2ab184b906885ba21f5d6905490bbc5d67d9f (diff)
downloadrtmux-ad71e7f9d247e4745cf80c7ec6f698e959adb99f.tar.gz
rtmux-ad71e7f9d247e4745cf80c7ec6f698e959adb99f.tar.bz2
rtmux-ad71e7f9d247e4745cf80c7ec6f698e959adb99f.zip
Calculate size when trimming RHS correctly.
Diffstat (limited to 'tty.c')
-rw-r--r--tty.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/tty.c b/tty.c
index 10ae1617..bf4c1424 100644
--- a/tty.c
+++ b/tty.c
@@ -936,8 +936,13 @@ tty_clamp_line(struct tty *tty, const struct tty_ctx *ctx, u_int px, u_int py,
/* Right not visible. */
*i = 0;
*x = (ctx->xoff + px) - ctx->ox;
- *rx = nx - ((ctx->xoff + px) + nx - ctx->sx);
+ *rx = ctx->sx - *x;
}
+ if (*rx > nx)
+ fatalx("%s: x too big, %u > %u", __func__, *rx, nx);
+ if (nx > *rx)
+ *rx = nx;
+
return (1);
}
@@ -1028,8 +1033,13 @@ tty_clamp_area(struct tty *tty, const struct tty_ctx *ctx, u_int px, u_int py,
/* Right not visible. */
*i = 0;
*x = (ctx->xoff + px) - ctx->ox;
- *rx = nx - ((ctx->xoff + px) + nx - ctx->sx);
+ *rx = ctx->sx - *x;
}
+ if (*rx > nx)
+ fatalx("%s: x too big, %u > %u", __func__, *rx, nx);
+ if (nx > *rx)
+ *rx = nx;
+
if (yoff >= ctx->oy && yoff + ny <= ctx->oy + ctx->sy) {
/* All visible. */
*j = 0;
@@ -1049,8 +1059,13 @@ tty_clamp_area(struct tty *tty, const struct tty_ctx *ctx, u_int px, u_int py,
/* Right not visible. */
*j = 0;
*y = (ctx->yoff + py) - ctx->oy;
- *ry = ny - ((ctx->yoff + py) + ny - ctx->sy);
+ *ry = ctx->sy - *y;
}
+ if (*ry > ny)
+ fatalx("%s: y too big, %u > %u", __func__, *ry, ny);
+ if (ny > *ry)
+ *ry = ny;
+
return (1);
}