From 7e6bbc63aba8e39e783050c767ae9be8487ef312 Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Wed, 18 Mar 2026 13:04:21 +0000 Subject: [PATCH] Fix a slew of possible int vs u_int bugs which would likely have caused an overflow crash. --- cmd-new-pane.c | 21 ++++++++------- cmd-resize-pane.c | 45 ++++++++++++++++--------------- format.c | 14 +++++----- layout-custom.c | 9 ++++--- layout.c | 24 ++++++++++------- screen-redraw.c | 32 +++++++++++----------- server-client.c | 62 +++++++++++++++++++++++------------------- tmux.h | 7 +++-- tty.c | 6 +++-- window.c | 68 ++++++++++++++++++++++++++--------------------- 10 files changed, 155 insertions(+), 133 deletions(-) diff --git a/cmd-new-pane.c b/cmd-new-pane.c index a014aec6..a99180e7 100644 --- a/cmd-new-pane.c +++ b/cmd-new-pane.c @@ -66,8 +66,9 @@ cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item) char *cause = NULL, *cp; struct args_value *av; u_int count = args_count(args); - u_int x, y, sx, sy, pct; - static u_int last_x = 0, last_y = 0; + int x, y; + u_int sx, sy, pct; + static int last_x = 0, last_y = 0; if (args_has(args, 'f')) { sx = w->sx; @@ -96,7 +97,7 @@ cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item) } } if (args_has(args, 'w')) { - sx = args_strtonum_and_expand(args, 'w', 0, w->sx, item, + sx = args_strtonum_and_expand(args, 'w', 1, USHRT_MAX, item, &cause); if (cause != NULL) { cmdq_error(item, "size %s", cause); @@ -105,7 +106,7 @@ cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item) } } if (args_has(args, 'h')) { - sy = args_strtonum_and_expand(args, 'h', 0, w->sy, item, + sy = args_strtonum_and_expand(args, 'h', 1, USHRT_MAX, item, &cause); if (cause != NULL) { cmdq_error(item, "size %s", cause); @@ -114,8 +115,8 @@ cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item) } } if (args_has(args, 'x')) { - x = args_strtonum_and_expand(args, 'x', 0, w->sx, item, - &cause); + x = args_strtonum_and_expand(args, 'x', SHRT_MIN, SHRT_MAX, + item, &cause); if (cause != NULL) { cmdq_error(item, "size %s", cause); free(cause); @@ -126,13 +127,13 @@ cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item) x = 5; } else { x = (last_x += 5); - if (last_x > w->sx) + if (last_x > (int)w->sx) x = 5; } } if (args_has(args, 'y')) { - y = args_strtonum_and_expand(args, 'y', 0, w->sx, item, - &cause); + y = args_strtonum_and_expand(args, 'y', SHRT_MIN, SHRT_MAX, + item, &cause); if (cause != NULL) { cmdq_error(item, "size %s", cause); free(cause); @@ -143,7 +144,7 @@ cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item) y = 5; } else { y = (last_y += 5); - if (last_y > w->sy) + if (last_y > (int)w->sy) y = 5; } } diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c index 5abbaa3c..e1d6438d 100644 --- a/cmd-resize-pane.c +++ b/cmd-resize-pane.c @@ -164,7 +164,8 @@ cmd_resize_pane_mouse_update_floating(struct client *c, struct mouse_event *m) struct window *w; struct window_pane *wp; struct layout_cell *lc; - u_int y, ly, x, lx, new_sx, new_sy; + u_int y, ly, x, lx; + int new_sx, new_sy; int new_xoff, new_yoff, resizes = 0; wl = cmd_mouse_window(m, NULL); @@ -188,83 +189,83 @@ cmd_resize_pane_mouse_update_floating(struct client *c, struct mouse_event *m) wp = c->tty.mouse_wp; lc = wp->layout_cell; - log_debug("%s: %%%u resize_pane xoff=%u sx=%u xy=%ux%u lxy=%ux%u", + log_debug("%s: %%%u resize_pane xoff=%d sx=%u xy=%ux%u lxy=%ux%u", __func__, wp->id, wp->xoff, wp->sx, x, y, lx, ly); if ((((int)lx == wp->xoff - 1) || ((int)lx == wp->xoff)) && ((int)ly == wp->yoff - 1)) { /* Top left corner */ - new_sx = lc->sx + (lx - x); + new_sx = (int)lc->sx + ((int)lx - (int)x); if (new_sx < PANE_MINIMUM) new_sx = PANE_MINIMUM; - new_sy = lc->sy + (ly - y); + new_sy = (int)lc->sy + ((int)ly - (int)y); if (new_sy < PANE_MINIMUM) new_sy = PANE_MINIMUM; new_xoff = x + 1; /* Because mouse is on border at xoff - 1 */ new_yoff = y + 1; - layout_set_size(lc, new_sx, new_sy, new_xoff, new_yoff); + layout_set_size(lc, (u_int)new_sx, (u_int)new_sy, new_xoff, new_yoff); resizes++; } else if ((((int)lx == wp->xoff + (int)wp->sx + 1) || ((int)lx == wp->xoff + (int)wp->sx)) && ((int)ly == wp->yoff - 1)) { /* Top right corner */ - new_sx = x - lc->xoff; + new_sx = (int)x - lc->xoff; if (new_sx < PANE_MINIMUM) new_sx = PANE_MINIMUM; - new_sy = lc->sy + (ly - y); + new_sy = (int)lc->sy + ((int)ly - (int)y); if (new_sy < PANE_MINIMUM) new_sy = PANE_MINIMUM; new_yoff = y + 1; - layout_set_size(lc, new_sx, new_sy, lc->xoff, new_yoff); + layout_set_size(lc, (u_int)new_sx, (u_int)new_sy, lc->xoff, new_yoff); resizes++; } else if ((((int)lx == wp->xoff - 1) || ((int)lx == wp->xoff)) && ((int)ly == wp->yoff + (int)wp->sy)) { /* Bottom left corner */ - new_sx = lc->sx + (lx - x); + new_sx = (int)lc->sx + ((int)lx - (int)x); if (new_sx < PANE_MINIMUM) new_sx = PANE_MINIMUM; - new_sy = y - lc->yoff; + new_sy = (int)y - lc->yoff; if (new_sy < PANE_MINIMUM) return; new_xoff = x + 1; - layout_set_size(lc, new_sx, new_sy, new_xoff, lc->yoff); + layout_set_size(lc, (u_int)new_sx, (u_int)new_sy, new_xoff, lc->yoff); resizes++; } else if ((((int)lx == wp->xoff + (int)wp->sx + 1) || ((int)lx == wp->xoff + (int)wp->sx)) && ((int)ly == wp->yoff + (int)wp->sy)) { /* Bottom right corner */ - new_sx = x - lc->xoff; + new_sx = (int)x - lc->xoff; if (new_sx < PANE_MINIMUM) new_sx = PANE_MINIMUM; - new_sy = y - lc->yoff; + new_sy = (int)y - lc->yoff; if (new_sy < PANE_MINIMUM) new_sy = PANE_MINIMUM; - layout_set_size(lc, new_sx, new_sy, lc->xoff, lc->yoff); + layout_set_size(lc, (u_int)new_sx, (u_int)new_sy, lc->xoff, lc->yoff); resizes++; } else if ((int)lx == wp->xoff + (int)wp->sx + 1) { /* Right border */ - new_sx = x - lc->xoff; + new_sx = (int)x - lc->xoff; if (new_sx < PANE_MINIMUM) return; - layout_set_size(lc, new_sx, lc->sy, lc->xoff, lc->yoff); + layout_set_size(lc, (u_int)new_sx, lc->sy, lc->xoff, lc->yoff); resizes++; } else if ((int)lx == wp->xoff - 1) { /* Left border */ - new_sx = lc->sx + (lx - x); + new_sx = (int)lc->sx + ((int)lx - (int)x); if (new_sx < PANE_MINIMUM) return; new_xoff = x + 1; - layout_set_size(lc, new_sx, lc->sy, new_xoff, lc->yoff); + layout_set_size(lc, (u_int)new_sx, lc->sy, new_xoff, lc->yoff); resizes++; } else if ((int)ly == wp->yoff + (int)wp->sy) { /* Bottom border */ - new_sy = y - lc->yoff; + new_sy = (int)y - lc->yoff; if (new_sy < PANE_MINIMUM) return; - layout_set_size(lc, lc->sx, new_sy, lc->xoff, lc->yoff); + layout_set_size(lc, lc->sx, (u_int)new_sy, lc->xoff, lc->yoff); resizes++; } else if ((int)ly == wp->yoff - 1) { /* Top border (move instead of resize) */ - new_xoff = lc->xoff + (x - lx); + new_xoff = lc->xoff + ((int)x - (int)lx); new_yoff = y + 1; layout_set_size(lc, lc->sx, lc->sy, new_xoff, new_yoff); /* To resize instead of move: @@ -276,7 +277,7 @@ cmd_resize_pane_mouse_update_floating(struct client *c, struct mouse_event *m) */ resizes++; } else { - log_debug("%s: %%%u resize_pane xoff=%u sx=%u xy=%ux%u lxy=%ux%u ", + log_debug("%s: %%%u resize_pane xoff=%d sx=%u xy=%ux%u lxy=%ux%u ", __func__, wp->id, wp->xoff, wp->sx, x, y, lx, ly); } if (resizes != 0) { diff --git a/format.c b/format.c index 398161e7..18fc9a1a 100644 --- a/format.c +++ b/format.c @@ -1160,9 +1160,9 @@ format_cb_pane_at_bottom(struct format_tree *ft) status = options_get_number(w->options, "pane-border-status"); if (status == PANE_STATUS_BOTTOM) - flag = (wp->yoff + wp->sy == w->sy - 1); + flag = (wp->yoff + (int)wp->sy == (int)w->sy - 1); else - flag = (wp->yoff + wp->sy == w->sy); + flag = (wp->yoff + (int)wp->sy == (int)w->sy); xasprintf(&value, "%d", flag); return (value); } @@ -2006,7 +2006,7 @@ static void * format_cb_pane_at_right(struct format_tree *ft) { if (ft->wp != NULL) { - if (ft->wp->xoff + ft->wp->sx == ft->wp->window->sx) + if (ft->wp->xoff + (int)ft->wp->sx == (int)ft->wp->window->sx) return (xstrdup("1")); return (xstrdup("0")); } @@ -2018,7 +2018,7 @@ static void * format_cb_pane_bottom(struct format_tree *ft) { if (ft->wp != NULL) - return (format_printf("%u", ft->wp->yoff + ft->wp->sy - 1)); + return (format_printf("%d", ft->wp->yoff + (int)ft->wp->sy - 1)); return (NULL); } @@ -2177,7 +2177,7 @@ static void * format_cb_pane_left(struct format_tree *ft) { if (ft->wp != NULL) - return (format_printf("%u", ft->wp->xoff)); + return (format_printf("%d", ft->wp->xoff)); return (NULL); } @@ -2269,7 +2269,7 @@ static void * format_cb_pane_right(struct format_tree *ft) { if (ft->wp != NULL) - return (format_printf("%u", ft->wp->xoff + ft->wp->sx - 1)); + return (format_printf("%d", ft->wp->xoff + (int)ft->wp->sx - 1)); return (NULL); } @@ -2311,7 +2311,7 @@ static void * format_cb_pane_top(struct format_tree *ft) { if (ft->wp != NULL) - return (format_printf("%u", ft->wp->yoff)); + return (format_printf("%d", ft->wp->yoff)); return (NULL); } diff --git a/layout-custom.c b/layout-custom.c index 30f8909b..fc310fb6 100644 --- a/layout-custom.c +++ b/layout-custom.c @@ -104,10 +104,10 @@ layout_append(struct layout_cell *lc, char *buf, size_t len) if (lc == NULL) return (0); if (lc->wp != NULL) { - tmplen = xsnprintf(tmp, sizeof tmp, "%ux%u,%u,%u,%u", + tmplen = xsnprintf(tmp, sizeof tmp, "%ux%u,%d,%d,%u", lc->sx, lc->sy, lc->xoff, lc->yoff, lc->wp->id); } else { - tmplen = xsnprintf(tmp, sizeof tmp, "%ux%u,%u,%u", + tmplen = xsnprintf(tmp, sizeof tmp, "%ux%u,%d,%d", lc->sx, lc->sy, lc->xoff, lc->yoff); } if (tmplen > (sizeof tmp) - 1) @@ -349,12 +349,13 @@ static struct layout_cell * layout_construct_cell(struct layout_cell *lcparent, const char **layout) { struct layout_cell *lc; - u_int sx, sy, xoff, yoff; + u_int sx, sy; + int xoff, yoff; const char *saved; if (!isdigit((u_char) **layout)) return (NULL); - if (sscanf(*layout, "%ux%u,%u,%u", &sx, &sy, &xoff, &yoff) != 4) + if (sscanf(*layout, "%ux%u,%d,%d", &sx, &sy, &xoff, &yoff) != 4) return (NULL); while (isdigit((u_char) **layout)) diff --git a/layout.c b/layout.c index 29912810..ca85a7af 100644 --- a/layout.c +++ b/layout.c @@ -61,8 +61,8 @@ layout_create_cell(struct layout_cell *lcparent) lc->sx = UINT_MAX; lc->sy = UINT_MAX; - lc->xoff = UINT_MAX; - lc->yoff = UINT_MAX; + lc->xoff = INT_MAX; + lc->yoff = INT_MAX; lc->wp = NULL; @@ -133,7 +133,7 @@ layout_print_cell(struct layout_cell *lc, const char *hdr, u_int n) type = "UNKNOWN"; break; } - log_debug("%s:%*s%p type %s [parent %p] wp=%p [%u,%u %ux%u]", hdr, n, + log_debug("%s:%*s%p type %s [parent %p] wp=%p [%d,%d %ux%u]", hdr, n, " ", lc, type, lc->parent, lc->wp, lc->xoff, lc->yoff, lc->sx, lc->sy); switch (lc->type) { @@ -154,8 +154,10 @@ layout_search_by_border(struct layout_cell *lc, u_int x, u_int y) struct layout_cell *lcchild, *last = NULL; TAILQ_FOREACH(lcchild, &lc->cells, entry) { - if (x >= lcchild->xoff && x < lcchild->xoff + lcchild->sx && - y >= lcchild->yoff && y < lcchild->yoff + lcchild->sy) { + if ((int)x >= lcchild->xoff && + (int)x < lcchild->xoff + (int)lcchild->sx && + (int)y >= lcchild->yoff && + (int)y < lcchild->yoff + (int)lcchild->sy) { /* Inside the cell - recurse. */ return (layout_search_by_border(lcchild, x, y)); } @@ -167,11 +169,13 @@ layout_search_by_border(struct layout_cell *lc, u_int x, u_int y) switch (lc->type) { case LAYOUT_LEFTRIGHT: - if (x < lcchild->xoff && x >= last->xoff + last->sx) + if ((int)x < lcchild->xoff && + (int)x >= last->xoff + (int)last->sx) return (last); break; case LAYOUT_TOPBOTTOM: - if (y < lcchild->yoff && y >= last->yoff + last->sy) + if ((int)y < lcchild->yoff && + (int)y >= last->yoff + (int)last->sy) return (last); break; case LAYOUT_WINDOWPANE: @@ -186,8 +190,8 @@ layout_search_by_border(struct layout_cell *lc, u_int x, u_int y) } void -layout_set_size(struct layout_cell *lc, u_int sx, u_int sy, u_int xoff, - u_int yoff) +layout_set_size(struct layout_cell *lc, u_int sx, u_int sy, int xoff, + int yoff) { lc->sx = sx; lc->sy = sy; @@ -249,7 +253,7 @@ static void layout_fix_offsets1(struct layout_cell *lc) { struct layout_cell *lcchild; - u_int xoff, yoff; + int xoff, yoff; if (lc->type == LAYOUT_LEFTRIGHT) { xoff = lc->xoff; diff --git a/screen-redraw.c b/screen-redraw.c index 2fcfe43b..259fc173 100644 --- a/screen-redraw.c +++ b/screen-redraw.c @@ -443,7 +443,7 @@ screen_redraw_check_cell(struct screen_redraw_ctx *ctx, u_int px, u_int py, int pane_status = ctx->pane_status; u_int sx = w->sx, sy = w->sy; int border, pane_scrollbars = ctx->pane_scrollbars; - u_int pane_status_line; + int pane_status_line; int sb_pos = ctx->pane_scrollbars_pos; int sb_w, left, right, tiled_only=0; @@ -526,11 +526,11 @@ screen_redraw_check_cell(struct screen_redraw_ctx *ctx, u_int px, u_int py, if (pane_status == PANE_STATUS_TOP) pane_status_line = wp->yoff - 1; else - pane_status_line = wp->yoff + wp->sy; + pane_status_line = wp->yoff + (int)wp->sy; left = wp->xoff + 2; - right = wp->xoff + 2 + wp->status_size - 1; + right = wp->xoff + 2 + (int)wp->status_size - 1; - if (py == pane_status_line + ctx->oy && /* XXX unsure about adding oy here, needs more testing. */ + if ((int)py == pane_status_line + (int)ctx->oy && (int)px >= left && (int)px <= right) return (CELL_INSIDE); } @@ -1289,8 +1289,8 @@ screen_redraw_draw_pane(struct screen_redraw_ctx *ctx, struct window_pane *wp) log_debug("%s: %s @%u %%%u", __func__, c->name, w->id, wp->id); - if (wp->xoff + (int)wp->sx <= ctx->ox || - wp->xoff >= ctx->ox + (int)ctx->sx) + if (wp->xoff + (int)wp->sx <= (int)ctx->ox || + wp->xoff >= (int)ctx->ox + (int)ctx->sx) return; /* woy is window y offset in tty. */ @@ -1300,8 +1300,8 @@ screen_redraw_draw_pane(struct screen_redraw_ctx *ctx, struct window_pane *wp) woy = 0; for (j = 0; j < wp->sy; j++) { - if (wp->yoff + (int)j < ctx->oy || - wp->yoff + j >= ctx->oy + ctx->sy) + if (wp->yoff + (int)j < (int)ctx->oy || + wp->yoff + (int)j >= (int)ctx->oy + (int)ctx->sy) continue; wy = wp->yoff + j; /* y line within window w. */ py = woy + wy - ctx->oy; /* y line within tty. */ @@ -1312,27 +1312,27 @@ screen_redraw_draw_pane(struct screen_redraw_ctx *ctx, struct window_pane *wp) /* Note: i is apparenty not used now that the vr array * returns where in s to read from. */ - if (wp->xoff >= ctx->ox && - wp->xoff + wp->sx <= ctx->ox + ctx->sx) { + if (wp->xoff >= (int)ctx->ox && + wp->xoff + (int)wp->sx <= (int)ctx->ox + (int)ctx->sx) { /* All visible. */ i = 0; - wx = wp->xoff - ctx->ox; + wx = (u_int)(wp->xoff - (int)ctx->ox); width = wp->sx; - } else if (wp->xoff < ctx->ox && - wp->xoff + wp->sx > ctx->ox + ctx->sx) { + } else if (wp->xoff < (int)ctx->ox && + wp->xoff + (int)wp->sx > (int)ctx->ox + (int)ctx->sx) { /* Both left and right not visible. */ i = ctx->ox; wx = 0; width = ctx->sx; - } else if (wp->xoff < ctx->ox) { + } else if (wp->xoff < (int)ctx->ox) { /* Left not visible. */ - i = ctx->ox - wp->xoff; + i = (u_int)((int)ctx->ox - wp->xoff); wx = 0; width = wp->sx - i; } else { /* Right not visible. */ i = 0; - wx = wp->xoff - ctx->ox; + wx = (u_int)(wp->xoff - (int)ctx->ox); width = ctx->sx - wx; } log_debug("%s: %s %%%u line %u,%u at %u,%u, width %u", diff --git a/server-client.c b/server-client.c index 4f85710e..ab67d49a 100644 --- a/server-client.c +++ b/server-client.c @@ -617,8 +617,8 @@ server_client_check_mouse_in_pane(struct window_pane *wp, u_int px, u_int py, struct options *wo = w->options; struct window_pane *fwp; int pane_status, sb, sb_pos, sb_w, sb_pad; - u_int pane_status_line, sl_top, sl_bottom; - u_int bdr_bottom, bdr_top, bdr_left, bdr_right; + int pane_status_line, sl_top, sl_bottom; + int bdr_bottom, bdr_top, bdr_left, bdr_right; sb = options_get_number(wo, "pane-scrollbars"); sb_pos = options_get_number(wo, "pane-scrollbars-position"); @@ -641,29 +641,30 @@ server_client_check_mouse_in_pane(struct window_pane *wp, u_int px, u_int py, /* Check if point is within the pane or scrollbar. */ if (((pane_status != PANE_STATUS_OFF && - py != pane_status_line && py != wp->yoff + wp->sy) || + (int)py != pane_status_line && (int)py != wp->yoff + (int)wp->sy) || (wp->yoff == 0 && py < wp->sy) || - ((int)py >= wp->yoff && py < wp->yoff + wp->sy)) && + ((int)py >= wp->yoff && (int)py < wp->yoff + (int)wp->sy)) && ((sb_pos == PANE_SCROLLBARS_RIGHT && - px < wp->xoff + wp->sx + sb_pad + sb_w) || + (int)px < wp->xoff + (int)wp->sx + sb_pad + sb_w) || (sb_pos == PANE_SCROLLBARS_LEFT && - px < wp->xoff + wp->sx - sb_pad - sb_w))) { + (int)px < wp->xoff + (int)wp->sx - sb_pad - sb_w))) { /* Check if in the scrollbar. */ if ((sb_pos == PANE_SCROLLBARS_RIGHT && - (px >= wp->xoff + wp->sx + sb_pad && - px < wp->xoff + wp->sx + sb_pad + sb_w)) || + ((int)px >= wp->xoff + (int)wp->sx + sb_pad && + (int)px < wp->xoff + (int)wp->sx + sb_pad + sb_w)) || (sb_pos == PANE_SCROLLBARS_LEFT && ((int)px >= wp->xoff - sb_pad - sb_w && (int)px < wp->xoff - sb_pad))) { /* Check where inside the scrollbar. */ - sl_top = wp->yoff + wp->sb_slider_y; - sl_bottom = (wp->yoff + wp->sb_slider_y + - wp->sb_slider_h - 1); - if (py < sl_top) + sl_top = wp->yoff + (int)wp->sb_slider_y; + sl_bottom = wp->yoff + (int)wp->sb_slider_y + + (int)wp->sb_slider_h - 1; + if ((int)py < sl_top) return (SCROLLBAR_UP); - else if (py >= sl_top && - py <= sl_bottom) { - *sl_mpos = (py - wp->sb_slider_y - wp->yoff); + else if ((int)py >= sl_top && + (int)py <= sl_bottom) { + *sl_mpos = ((int)py - (int)wp->sb_slider_y - + wp->yoff); return (SCROLLBAR_SLIDER); } else /* py > sl_bottom */ return (SCROLLBAR_DOWN); @@ -681,28 +682,31 @@ server_client_check_mouse_in_pane(struct window_pane *wp, u_int px, u_int py, /* Try the pane borders if not zoomed. */ TAILQ_FOREACH(fwp, &w->panes, entry) { if (sb_pos == PANE_SCROLLBARS_LEFT) - bdr_right = fwp->xoff + fwp->sx; + bdr_right = fwp->xoff + (int)fwp->sx; else /* PANE_SCROLLBARS_RIGHT or none. */ - bdr_right = fwp->xoff + fwp->sx + sb_pad + sb_w; - if ((int)py >= fwp->yoff - 1 && py <= fwp->yoff + fwp->sy) { - if (px == bdr_right) + bdr_right = fwp->xoff + (int)fwp->sx + + sb_pad + sb_w; + if ((int)py >= fwp->yoff - 1 && + (int)py <= fwp->yoff + (int)fwp->sy) { + if ((int)px == bdr_right) break; if (wp->flags & PANE_FLOATING) { /* Floating pane, check if left border. */ bdr_left = fwp->xoff - 1; - if (px == bdr_left) + if ((int)px == bdr_left) break; } } - if ((int)px >= fwp->xoff - 1 && px <= fwp->xoff + fwp->sx) { - bdr_bottom = fwp->yoff + fwp->sy; - if (py == bdr_bottom) + if ((int)px >= fwp->xoff - 1 && + (int)px <= fwp->xoff + (int)fwp->sx) { + bdr_bottom = fwp->yoff + (int)fwp->sy; + if ((int)py == bdr_bottom) break; if (wp->flags & PANE_FLOATING) { /* Floating pane, check if top border. */ bdr_top = fwp->yoff - 1; - if (py == bdr_top) + if ((int)py == bdr_top) break; } } @@ -3088,12 +3092,14 @@ server_client_reset_state(struct client *c) } else if (wp != NULL && c->overlay_draw == NULL) { cursor = 0; tty_window_offset(tty, &ox, &oy, &sx, &sy); - if (wp->xoff + s->cx >= ox && wp->xoff + s->cx <= ox + sx && - wp->yoff + s->cy >= oy && wp->yoff + s->cy <= oy + sy) { + if (wp->xoff + (int)s->cx >= (int)ox && + wp->xoff + (int)s->cx <= (int)ox + (int)sx && + wp->yoff + (int)s->cy >= (int)oy && + wp->yoff + (int)s->cy <= (int)oy + (int)sy) { cursor = 1; - cx = wp->xoff + s->cx - ox; - cy = wp->yoff + s->cy - oy; + cx = (u_int)(wp->xoff + (int)s->cx - (int)ox); + cy = (u_int)(wp->yoff + (int)s->cy - (int)oy); if (status_at_line(c) == 0) cy += status_line_size(c); diff --git a/tmux.h b/tmux.h index c9d3c04c..bfc5f8bb 100644 --- a/tmux.h +++ b/tmux.h @@ -1423,8 +1423,8 @@ struct layout_cell { u_int sx; u_int sy; - u_int xoff; - u_int yoff; + int xoff; + int yoff; struct window_pane *wp; struct layout_cells cells; @@ -3439,8 +3439,7 @@ void layout_unminimise_cell(struct window *, struct layout_cell *); void layout_resize_layout(struct window *, struct layout_cell *, enum layout_type, int, int); struct layout_cell *layout_search_by_border(struct layout_cell *, u_int, u_int); -void layout_set_size(struct layout_cell *, u_int, u_int, u_int, - u_int); +void layout_set_size(struct layout_cell *, u_int, u_int, int, int); void layout_make_leaf(struct layout_cell *, struct window_pane *); void layout_make_node(struct layout_cell *, enum layout_type); void layout_fix_zindexes(struct window *, struct layout_cell *); diff --git a/tty.c b/tty.c index 5c790616..f533b9df 100644 --- a/tty.c +++ b/tty.c @@ -1319,9 +1319,11 @@ tty_clear_area(struct tty *tty, const struct tty_ctx *ctx, u_int py, TAILQ_FOREACH(wpl, &w->z_index, zentry) { if (wpl == wp || ~wpl->flags & PANE_FLOATING) continue; - if ((int)wpl->xoff - 1 > (int)(px + nx) || wpl->xoff + wpl->sx + 1 < px) + if ((int)wpl->xoff - 1 > (int)(px + nx) || + wpl->xoff + (int)wpl->sx + 1 < (int)px) continue; - if ((int)wpl->yoff - 1 > (int)(py + ny) || wpl->yoff + wpl->sy + 1 < py) + if ((int)wpl->yoff - 1 > (int)(py + ny) || + wpl->yoff + (int)wpl->sy + 1 < (int)py) continue; overlap++; if (overlap > 0) break; diff --git a/window.c b/window.c index d1a2219e..7dd89928 100644 --- a/window.c +++ b/window.c @@ -71,7 +71,7 @@ static struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int); static void window_pane_destroy(struct window_pane *); static void window_pane_full_size_offset(struct window_pane *wp, - u_int *xoff, u_int *yoff, u_int *sx, u_int *sy); + int *xoff, int *yoff, u_int *sx, u_int *sy); RB_GENERATE(windows, window, entry, window_cmp); RB_GENERATE(winlinks, winlink, entry, winlink_cmp); @@ -1469,7 +1469,7 @@ window_pane_choose_best(struct window_pane **list, u_int size) * scrollbars if they were visible but not including the border(s). */ static void -window_pane_full_size_offset(struct window_pane *wp, u_int *xoff, u_int *yoff, +window_pane_full_size_offset(struct window_pane *wp, int *xoff, int *yoff, u_int *sx, u_int *sy) { struct window *w = wp->window; @@ -1503,9 +1503,11 @@ window_pane_find_up(struct window_pane *wp) { struct window *w; struct window_pane *next, *best, **list; - u_int edge, left, right, end, size; + int edge, left, right, end; + u_int size; int status, found; - u_int xoff, yoff, sx, sy; + int xoff, yoff; + u_int sx, sy; if (wp == NULL) return (NULL); @@ -1520,25 +1522,25 @@ window_pane_find_up(struct window_pane *wp) edge = yoff; if (status == PANE_STATUS_TOP) { if (edge == 1) - edge = w->sy + 1; + edge = (int)w->sy + 1; } else if (status == PANE_STATUS_BOTTOM) { if (edge == 0) - edge = w->sy; + edge = (int)w->sy; } else { if (edge == 0) - edge = w->sy + 1; + edge = (int)w->sy + 1; } left = xoff; - right = xoff + sx; + right = xoff + (int)sx; TAILQ_FOREACH(next, &w->panes, entry) { window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy); if (next == wp) continue; - if (yoff + sy + 1 != edge) + if (yoff + (int)sy + 1 != edge) continue; - end = xoff + sx - 1; + end = xoff + (int)sx - 1; found = 0; if (xoff < left && end > right) @@ -1564,9 +1566,11 @@ window_pane_find_down(struct window_pane *wp) { struct window *w; struct window_pane *next, *best, **list; - u_int edge, left, right, end, size; + int edge, left, right, end; + u_int size; int status, found; - u_int xoff, yoff, sx, sy; + int xoff, yoff; + u_int sx, sy; if (wp == NULL) return (NULL); @@ -1578,20 +1582,20 @@ window_pane_find_down(struct window_pane *wp) window_pane_full_size_offset(wp, &xoff, &yoff, &sx, &sy); - edge = yoff + sy + 1; + edge = yoff + (int)sy + 1; if (status == PANE_STATUS_TOP) { - if (edge >= w->sy) + if (edge >= (int)w->sy) edge = 1; } else if (status == PANE_STATUS_BOTTOM) { - if (edge >= w->sy - 1) + if (edge >= (int)w->sy - 1) edge = 0; } else { - if (edge >= w->sy) + if (edge >= (int)w->sy) edge = 0; } left = wp->xoff; - right = wp->xoff + wp->sx; + right = wp->xoff + (int)wp->sx; TAILQ_FOREACH(next, &w->panes, entry) { window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy); @@ -1599,7 +1603,7 @@ window_pane_find_down(struct window_pane *wp) continue; if (yoff != edge) continue; - end = xoff + sx - 1; + end = xoff + (int)sx - 1; found = 0; if (xoff < left && end > right) @@ -1625,9 +1629,11 @@ window_pane_find_left(struct window_pane *wp) { struct window *w; struct window_pane *next, *best, **list; - u_int edge, top, bottom, end, size; + int edge, top, bottom, end; + u_int size; int found; - u_int xoff, yoff, sx, sy; + int xoff, yoff; + u_int sx, sy; if (wp == NULL) return (NULL); @@ -1640,18 +1646,18 @@ window_pane_find_left(struct window_pane *wp) edge = xoff; if (edge == 0) - edge = w->sx + 1; + edge = (int)w->sx + 1; top = yoff; - bottom = yoff + sy; + bottom = yoff + (int)sy; TAILQ_FOREACH(next, &w->panes, entry) { window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy); if (next == wp) continue; - if (xoff + sx + 1 != edge) + if (xoff + (int)sx + 1 != edge) continue; - end = yoff + sy - 1; + end = yoff + (int)sy - 1; found = 0; if (yoff < top && end > bottom) @@ -1677,9 +1683,11 @@ window_pane_find_right(struct window_pane *wp) { struct window *w; struct window_pane *next, *best, **list; - u_int edge, top, bottom, end, size; + int edge, top, bottom, end; + u_int size; int found; - u_int xoff, yoff, sx, sy; + int xoff, yoff; + u_int sx, sy; if (wp == NULL) return (NULL); @@ -1690,12 +1698,12 @@ window_pane_find_right(struct window_pane *wp) window_pane_full_size_offset(wp, &xoff, &yoff, &sx, &sy); - edge = xoff + sx + 1; - if (edge >= w->sx) + edge = xoff + (int)sx + 1; + if (edge >= (int)w->sx) edge = 0; top = wp->yoff; - bottom = wp->yoff + wp->sy; + bottom = wp->yoff + (int)wp->sy; TAILQ_FOREACH(next, &w->panes, entry) { window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy); @@ -1703,7 +1711,7 @@ window_pane_find_right(struct window_pane *wp) continue; if (xoff != edge) continue; - end = yoff + sy - 1; + end = yoff + (int)sy - 1; found = 0; if (yoff < top && end > bottom)