Fix a slew of possible int vs u_int bugs which would likely have caused an overflow crash.

This commit is contained in:
Michael Grant
2026-03-18 13:04:21 +00:00
parent 0d195698f8
commit 7e6bbc63ab
10 changed files with 155 additions and 133 deletions

View File

@@ -66,8 +66,9 @@ cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item)
char *cause = NULL, *cp; char *cause = NULL, *cp;
struct args_value *av; struct args_value *av;
u_int count = args_count(args); u_int count = args_count(args);
u_int x, y, sx, sy, pct; int x, y;
static u_int last_x = 0, last_y = 0; u_int sx, sy, pct;
static int last_x = 0, last_y = 0;
if (args_has(args, 'f')) { if (args_has(args, 'f')) {
sx = w->sx; sx = w->sx;
@@ -96,7 +97,7 @@ cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item)
} }
} }
if (args_has(args, 'w')) { 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); &cause);
if (cause != NULL) { if (cause != NULL) {
cmdq_error(item, "size %s", cause); 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')) { 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); &cause);
if (cause != NULL) { if (cause != NULL) {
cmdq_error(item, "size %s", cause); 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')) { if (args_has(args, 'x')) {
x = args_strtonum_and_expand(args, 'x', 0, w->sx, item, x = args_strtonum_and_expand(args, 'x', SHRT_MIN, SHRT_MAX,
&cause); item, &cause);
if (cause != NULL) { if (cause != NULL) {
cmdq_error(item, "size %s", cause); cmdq_error(item, "size %s", cause);
free(cause); free(cause);
@@ -126,13 +127,13 @@ cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item)
x = 5; x = 5;
} else { } else {
x = (last_x += 5); x = (last_x += 5);
if (last_x > w->sx) if (last_x > (int)w->sx)
x = 5; x = 5;
} }
} }
if (args_has(args, 'y')) { if (args_has(args, 'y')) {
y = args_strtonum_and_expand(args, 'y', 0, w->sx, item, y = args_strtonum_and_expand(args, 'y', SHRT_MIN, SHRT_MAX,
&cause); item, &cause);
if (cause != NULL) { if (cause != NULL) {
cmdq_error(item, "size %s", cause); cmdq_error(item, "size %s", cause);
free(cause); free(cause);
@@ -143,7 +144,7 @@ cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item)
y = 5; y = 5;
} else { } else {
y = (last_y += 5); y = (last_y += 5);
if (last_y > w->sy) if (last_y > (int)w->sy)
y = 5; y = 5;
} }
} }

View File

@@ -164,7 +164,8 @@ cmd_resize_pane_mouse_update_floating(struct client *c, struct mouse_event *m)
struct window *w; struct window *w;
struct window_pane *wp; struct window_pane *wp;
struct layout_cell *lc; 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; int new_xoff, new_yoff, resizes = 0;
wl = cmd_mouse_window(m, NULL); 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; wp = c->tty.mouse_wp;
lc = wp->layout_cell; 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); __func__, wp->id, wp->xoff, wp->sx, x, y, lx, ly);
if ((((int)lx == wp->xoff - 1) || ((int)lx == wp->xoff)) && if ((((int)lx == wp->xoff - 1) || ((int)lx == wp->xoff)) &&
((int)ly == wp->yoff - 1)) { ((int)ly == wp->yoff - 1)) {
/* Top left corner */ /* Top left corner */
new_sx = lc->sx + (lx - x); new_sx = (int)lc->sx + ((int)lx - (int)x);
if (new_sx < PANE_MINIMUM) if (new_sx < PANE_MINIMUM)
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) if (new_sy < PANE_MINIMUM)
new_sy = PANE_MINIMUM; new_sy = PANE_MINIMUM;
new_xoff = x + 1; /* Because mouse is on border at xoff - 1 */ new_xoff = x + 1; /* Because mouse is on border at xoff - 1 */
new_yoff = y + 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++; resizes++;
} else if ((((int)lx == wp->xoff + (int)wp->sx + 1) || } else if ((((int)lx == wp->xoff + (int)wp->sx + 1) ||
((int)lx == wp->xoff + (int)wp->sx)) && ((int)lx == wp->xoff + (int)wp->sx)) &&
((int)ly == wp->yoff - 1)) { ((int)ly == wp->yoff - 1)) {
/* Top right corner */ /* Top right corner */
new_sx = x - lc->xoff; new_sx = (int)x - lc->xoff;
if (new_sx < PANE_MINIMUM) if (new_sx < PANE_MINIMUM)
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) if (new_sy < PANE_MINIMUM)
new_sy = PANE_MINIMUM; new_sy = PANE_MINIMUM;
new_yoff = y + 1; 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++; resizes++;
} else if ((((int)lx == wp->xoff - 1) || ((int)lx == wp->xoff)) && } else if ((((int)lx == wp->xoff - 1) || ((int)lx == wp->xoff)) &&
((int)ly == wp->yoff + (int)wp->sy)) { ((int)ly == wp->yoff + (int)wp->sy)) {
/* Bottom left corner */ /* Bottom left corner */
new_sx = lc->sx + (lx - x); new_sx = (int)lc->sx + ((int)lx - (int)x);
if (new_sx < PANE_MINIMUM) if (new_sx < PANE_MINIMUM)
new_sx = PANE_MINIMUM; new_sx = PANE_MINIMUM;
new_sy = y - lc->yoff; new_sy = (int)y - lc->yoff;
if (new_sy < PANE_MINIMUM) if (new_sy < PANE_MINIMUM)
return; return;
new_xoff = x + 1; 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++; resizes++;
} else if ((((int)lx == wp->xoff + (int)wp->sx + 1) || } else if ((((int)lx == wp->xoff + (int)wp->sx + 1) ||
((int)lx == wp->xoff + (int)wp->sx)) && ((int)lx == wp->xoff + (int)wp->sx)) &&
((int)ly == wp->yoff + (int)wp->sy)) { ((int)ly == wp->yoff + (int)wp->sy)) {
/* Bottom right corner */ /* Bottom right corner */
new_sx = x - lc->xoff; new_sx = (int)x - lc->xoff;
if (new_sx < PANE_MINIMUM) if (new_sx < PANE_MINIMUM)
new_sx = PANE_MINIMUM; new_sx = PANE_MINIMUM;
new_sy = y - lc->yoff; new_sy = (int)y - lc->yoff;
if (new_sy < PANE_MINIMUM) if (new_sy < PANE_MINIMUM)
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++; resizes++;
} else if ((int)lx == wp->xoff + (int)wp->sx + 1) { } else if ((int)lx == wp->xoff + (int)wp->sx + 1) {
/* Right border */ /* Right border */
new_sx = x - lc->xoff; new_sx = (int)x - lc->xoff;
if (new_sx < PANE_MINIMUM) if (new_sx < PANE_MINIMUM)
return; 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++; resizes++;
} else if ((int)lx == wp->xoff - 1) { } else if ((int)lx == wp->xoff - 1) {
/* Left border */ /* Left border */
new_sx = lc->sx + (lx - x); new_sx = (int)lc->sx + ((int)lx - (int)x);
if (new_sx < PANE_MINIMUM) if (new_sx < PANE_MINIMUM)
return; return;
new_xoff = x + 1; 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++; resizes++;
} else if ((int)ly == wp->yoff + (int)wp->sy) { } else if ((int)ly == wp->yoff + (int)wp->sy) {
/* Bottom border */ /* Bottom border */
new_sy = y - lc->yoff; new_sy = (int)y - lc->yoff;
if (new_sy < PANE_MINIMUM) if (new_sy < PANE_MINIMUM)
return; 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++; resizes++;
} else if ((int)ly == wp->yoff - 1) { } else if ((int)ly == wp->yoff - 1) {
/* Top border (move instead of resize) */ /* Top border (move instead of resize) */
new_xoff = lc->xoff + (x - lx); new_xoff = lc->xoff + ((int)x - (int)lx);
new_yoff = y + 1; new_yoff = y + 1;
layout_set_size(lc, lc->sx, lc->sy, new_xoff, new_yoff); layout_set_size(lc, lc->sx, lc->sy, new_xoff, new_yoff);
/* To resize instead of move: /* To resize instead of move:
@@ -276,7 +277,7 @@ cmd_resize_pane_mouse_update_floating(struct client *c, struct mouse_event *m)
*/ */
resizes++; resizes++;
} else { } else {
log_debug("%s: %%%u resize_pane xoff=%u sx=%u xy=%ux%u lxy=%ux%u <else>", log_debug("%s: %%%u resize_pane xoff=%d sx=%u xy=%ux%u lxy=%ux%u <else>",
__func__, wp->id, wp->xoff, wp->sx, x, y, lx, ly); __func__, wp->id, wp->xoff, wp->sx, x, y, lx, ly);
} }
if (resizes != 0) { if (resizes != 0) {

View File

@@ -1160,9 +1160,9 @@ format_cb_pane_at_bottom(struct format_tree *ft)
status = options_get_number(w->options, "pane-border-status"); status = options_get_number(w->options, "pane-border-status");
if (status == PANE_STATUS_BOTTOM) if (status == PANE_STATUS_BOTTOM)
flag = (wp->yoff + wp->sy == w->sy - 1); flag = (wp->yoff + (int)wp->sy == (int)w->sy - 1);
else else
flag = (wp->yoff + wp->sy == w->sy); flag = (wp->yoff + (int)wp->sy == (int)w->sy);
xasprintf(&value, "%d", flag); xasprintf(&value, "%d", flag);
return (value); return (value);
} }
@@ -2006,7 +2006,7 @@ static void *
format_cb_pane_at_right(struct format_tree *ft) format_cb_pane_at_right(struct format_tree *ft)
{ {
if (ft->wp != NULL) { 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("1"));
return (xstrdup("0")); return (xstrdup("0"));
} }
@@ -2018,7 +2018,7 @@ static void *
format_cb_pane_bottom(struct format_tree *ft) format_cb_pane_bottom(struct format_tree *ft)
{ {
if (ft->wp != NULL) 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); return (NULL);
} }
@@ -2177,7 +2177,7 @@ static void *
format_cb_pane_left(struct format_tree *ft) format_cb_pane_left(struct format_tree *ft)
{ {
if (ft->wp != NULL) if (ft->wp != NULL)
return (format_printf("%u", ft->wp->xoff)); return (format_printf("%d", ft->wp->xoff));
return (NULL); return (NULL);
} }
@@ -2269,7 +2269,7 @@ static void *
format_cb_pane_right(struct format_tree *ft) format_cb_pane_right(struct format_tree *ft)
{ {
if (ft->wp != NULL) 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); return (NULL);
} }
@@ -2311,7 +2311,7 @@ static void *
format_cb_pane_top(struct format_tree *ft) format_cb_pane_top(struct format_tree *ft)
{ {
if (ft->wp != NULL) if (ft->wp != NULL)
return (format_printf("%u", ft->wp->yoff)); return (format_printf("%d", ft->wp->yoff));
return (NULL); return (NULL);
} }

View File

@@ -104,10 +104,10 @@ layout_append(struct layout_cell *lc, char *buf, size_t len)
if (lc == NULL) if (lc == NULL)
return (0); return (0);
if (lc->wp != NULL) { 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); lc->sx, lc->sy, lc->xoff, lc->yoff, lc->wp->id);
} else { } 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); lc->sx, lc->sy, lc->xoff, lc->yoff);
} }
if (tmplen > (sizeof tmp) - 1) if (tmplen > (sizeof tmp) - 1)
@@ -349,12 +349,13 @@ static struct layout_cell *
layout_construct_cell(struct layout_cell *lcparent, const char **layout) layout_construct_cell(struct layout_cell *lcparent, const char **layout)
{ {
struct layout_cell *lc; struct layout_cell *lc;
u_int sx, sy, xoff, yoff; u_int sx, sy;
int xoff, yoff;
const char *saved; const char *saved;
if (!isdigit((u_char) **layout)) if (!isdigit((u_char) **layout))
return (NULL); 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); return (NULL);
while (isdigit((u_char) **layout)) while (isdigit((u_char) **layout))

View File

@@ -61,8 +61,8 @@ layout_create_cell(struct layout_cell *lcparent)
lc->sx = UINT_MAX; lc->sx = UINT_MAX;
lc->sy = UINT_MAX; lc->sy = UINT_MAX;
lc->xoff = UINT_MAX; lc->xoff = INT_MAX;
lc->yoff = UINT_MAX; lc->yoff = INT_MAX;
lc->wp = NULL; lc->wp = NULL;
@@ -133,7 +133,7 @@ layout_print_cell(struct layout_cell *lc, const char *hdr, u_int n)
type = "UNKNOWN"; type = "UNKNOWN";
break; 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, type, lc->parent, lc->wp, lc->xoff, lc->yoff, lc->sx,
lc->sy); lc->sy);
switch (lc->type) { 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; struct layout_cell *lcchild, *last = NULL;
TAILQ_FOREACH(lcchild, &lc->cells, entry) { TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (x >= lcchild->xoff && x < lcchild->xoff + lcchild->sx && if ((int)x >= lcchild->xoff &&
y >= lcchild->yoff && y < lcchild->yoff + lcchild->sy) { (int)x < lcchild->xoff + (int)lcchild->sx &&
(int)y >= lcchild->yoff &&
(int)y < lcchild->yoff + (int)lcchild->sy) {
/* Inside the cell - recurse. */ /* Inside the cell - recurse. */
return (layout_search_by_border(lcchild, x, y)); 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) { switch (lc->type) {
case LAYOUT_LEFTRIGHT: 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); return (last);
break; break;
case LAYOUT_TOPBOTTOM: 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); return (last);
break; break;
case LAYOUT_WINDOWPANE: case LAYOUT_WINDOWPANE:
@@ -186,8 +190,8 @@ layout_search_by_border(struct layout_cell *lc, u_int x, u_int y)
} }
void void
layout_set_size(struct layout_cell *lc, u_int sx, u_int sy, u_int xoff, layout_set_size(struct layout_cell *lc, u_int sx, u_int sy, int xoff,
u_int yoff) int yoff)
{ {
lc->sx = sx; lc->sx = sx;
lc->sy = sy; lc->sy = sy;
@@ -249,7 +253,7 @@ static void
layout_fix_offsets1(struct layout_cell *lc) layout_fix_offsets1(struct layout_cell *lc)
{ {
struct layout_cell *lcchild; struct layout_cell *lcchild;
u_int xoff, yoff; int xoff, yoff;
if (lc->type == LAYOUT_LEFTRIGHT) { if (lc->type == LAYOUT_LEFTRIGHT) {
xoff = lc->xoff; xoff = lc->xoff;

View File

@@ -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; int pane_status = ctx->pane_status;
u_int sx = w->sx, sy = w->sy; u_int sx = w->sx, sy = w->sy;
int border, pane_scrollbars = ctx->pane_scrollbars; 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_pos = ctx->pane_scrollbars_pos;
int sb_w, left, right, tiled_only=0; 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) if (pane_status == PANE_STATUS_TOP)
pane_status_line = wp->yoff - 1; pane_status_line = wp->yoff - 1;
else else
pane_status_line = wp->yoff + wp->sy; pane_status_line = wp->yoff + (int)wp->sy;
left = wp->xoff + 2; 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) (int)px >= left && (int)px <= right)
return (CELL_INSIDE); 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); log_debug("%s: %s @%u %%%u", __func__, c->name, w->id, wp->id);
if (wp->xoff + (int)wp->sx <= ctx->ox || if (wp->xoff + (int)wp->sx <= (int)ctx->ox ||
wp->xoff >= ctx->ox + (int)ctx->sx) wp->xoff >= (int)ctx->ox + (int)ctx->sx)
return; return;
/* woy is window y offset in tty. */ /* 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; woy = 0;
for (j = 0; j < wp->sy; j++) { for (j = 0; j < wp->sy; j++) {
if (wp->yoff + (int)j < ctx->oy || if (wp->yoff + (int)j < (int)ctx->oy ||
wp->yoff + j >= ctx->oy + ctx->sy) wp->yoff + (int)j >= (int)ctx->oy + (int)ctx->sy)
continue; continue;
wy = wp->yoff + j; /* y line within window w. */ wy = wp->yoff + j; /* y line within window w. */
py = woy + wy - ctx->oy; /* y line within tty. */ 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 /* Note: i is apparenty not used now that the vr array
* returns where in s to read from. * returns where in s to read from.
*/ */
if (wp->xoff >= ctx->ox && if (wp->xoff >= (int)ctx->ox &&
wp->xoff + wp->sx <= ctx->ox + ctx->sx) { wp->xoff + (int)wp->sx <= (int)ctx->ox + (int)ctx->sx) {
/* All visible. */ /* All visible. */
i = 0; i = 0;
wx = wp->xoff - ctx->ox; wx = (u_int)(wp->xoff - (int)ctx->ox);
width = wp->sx; width = wp->sx;
} else if (wp->xoff < ctx->ox && } else if (wp->xoff < (int)ctx->ox &&
wp->xoff + wp->sx > ctx->ox + ctx->sx) { wp->xoff + (int)wp->sx > (int)ctx->ox + (int)ctx->sx) {
/* Both left and right not visible. */ /* Both left and right not visible. */
i = ctx->ox; i = ctx->ox;
wx = 0; wx = 0;
width = ctx->sx; width = ctx->sx;
} else if (wp->xoff < ctx->ox) { } else if (wp->xoff < (int)ctx->ox) {
/* Left not visible. */ /* Left not visible. */
i = ctx->ox - wp->xoff; i = (u_int)((int)ctx->ox - wp->xoff);
wx = 0; wx = 0;
width = wp->sx - i; width = wp->sx - i;
} else { } else {
/* Right not visible. */ /* Right not visible. */
i = 0; i = 0;
wx = wp->xoff - ctx->ox; wx = (u_int)(wp->xoff - (int)ctx->ox);
width = ctx->sx - wx; width = ctx->sx - wx;
} }
log_debug("%s: %s %%%u line %u,%u at %u,%u, width %u", log_debug("%s: %s %%%u line %u,%u at %u,%u, width %u",

View File

@@ -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 options *wo = w->options;
struct window_pane *fwp; struct window_pane *fwp;
int pane_status, sb, sb_pos, sb_w, sb_pad; int pane_status, sb, sb_pos, sb_w, sb_pad;
u_int pane_status_line, sl_top, sl_bottom; int pane_status_line, sl_top, sl_bottom;
u_int bdr_bottom, bdr_top, bdr_left, bdr_right; int bdr_bottom, bdr_top, bdr_left, bdr_right;
sb = options_get_number(wo, "pane-scrollbars"); sb = options_get_number(wo, "pane-scrollbars");
sb_pos = options_get_number(wo, "pane-scrollbars-position"); 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. */ /* Check if point is within the pane or scrollbar. */
if (((pane_status != PANE_STATUS_OFF && 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) || (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 && ((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 && (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. */ /* Check if in the scrollbar. */
if ((sb_pos == PANE_SCROLLBARS_RIGHT && if ((sb_pos == PANE_SCROLLBARS_RIGHT &&
(px >= wp->xoff + wp->sx + sb_pad && ((int)px >= wp->xoff + (int)wp->sx + sb_pad &&
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 && (sb_pos == PANE_SCROLLBARS_LEFT &&
((int)px >= wp->xoff - sb_pad - sb_w && ((int)px >= wp->xoff - sb_pad - sb_w &&
(int)px < wp->xoff - sb_pad))) { (int)px < wp->xoff - sb_pad))) {
/* Check where inside the scrollbar. */ /* Check where inside the scrollbar. */
sl_top = wp->yoff + wp->sb_slider_y; sl_top = wp->yoff + (int)wp->sb_slider_y;
sl_bottom = (wp->yoff + wp->sb_slider_y + sl_bottom = wp->yoff + (int)wp->sb_slider_y +
wp->sb_slider_h - 1); (int)wp->sb_slider_h - 1;
if (py < sl_top) if ((int)py < sl_top)
return (SCROLLBAR_UP); return (SCROLLBAR_UP);
else if (py >= sl_top && else if ((int)py >= sl_top &&
py <= sl_bottom) { (int)py <= sl_bottom) {
*sl_mpos = (py - wp->sb_slider_y - wp->yoff); *sl_mpos = ((int)py - (int)wp->sb_slider_y -
wp->yoff);
return (SCROLLBAR_SLIDER); return (SCROLLBAR_SLIDER);
} else /* py > sl_bottom */ } else /* py > sl_bottom */
return (SCROLLBAR_DOWN); 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. */ /* Try the pane borders if not zoomed. */
TAILQ_FOREACH(fwp, &w->panes, entry) { TAILQ_FOREACH(fwp, &w->panes, entry) {
if (sb_pos == PANE_SCROLLBARS_LEFT) if (sb_pos == PANE_SCROLLBARS_LEFT)
bdr_right = fwp->xoff + fwp->sx; bdr_right = fwp->xoff + (int)fwp->sx;
else else
/* PANE_SCROLLBARS_RIGHT or none. */ /* PANE_SCROLLBARS_RIGHT or none. */
bdr_right = fwp->xoff + fwp->sx + sb_pad + sb_w; bdr_right = fwp->xoff + (int)fwp->sx +
if ((int)py >= fwp->yoff - 1 && py <= fwp->yoff + fwp->sy) { sb_pad + sb_w;
if (px == bdr_right) if ((int)py >= fwp->yoff - 1 &&
(int)py <= fwp->yoff + (int)fwp->sy) {
if ((int)px == bdr_right)
break; break;
if (wp->flags & PANE_FLOATING) { if (wp->flags & PANE_FLOATING) {
/* Floating pane, check if left border. */ /* Floating pane, check if left border. */
bdr_left = fwp->xoff - 1; bdr_left = fwp->xoff - 1;
if (px == bdr_left) if ((int)px == bdr_left)
break; break;
} }
} }
if ((int)px >= fwp->xoff - 1 && px <= fwp->xoff + fwp->sx) { if ((int)px >= fwp->xoff - 1 &&
bdr_bottom = fwp->yoff + fwp->sy; (int)px <= fwp->xoff + (int)fwp->sx) {
if (py == bdr_bottom) bdr_bottom = fwp->yoff + (int)fwp->sy;
if ((int)py == bdr_bottom)
break; break;
if (wp->flags & PANE_FLOATING) { if (wp->flags & PANE_FLOATING) {
/* Floating pane, check if top border. */ /* Floating pane, check if top border. */
bdr_top = fwp->yoff - 1; bdr_top = fwp->yoff - 1;
if (py == bdr_top) if ((int)py == bdr_top)
break; break;
} }
} }
@@ -3088,12 +3092,14 @@ server_client_reset_state(struct client *c)
} else if (wp != NULL && c->overlay_draw == NULL) { } else if (wp != NULL && c->overlay_draw == NULL) {
cursor = 0; cursor = 0;
tty_window_offset(tty, &ox, &oy, &sx, &sy); tty_window_offset(tty, &ox, &oy, &sx, &sy);
if (wp->xoff + s->cx >= ox && wp->xoff + s->cx <= ox + sx && if (wp->xoff + (int)s->cx >= (int)ox &&
wp->yoff + s->cy >= oy && wp->yoff + s->cy <= oy + sy) { 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; cursor = 1;
cx = wp->xoff + s->cx - ox; cx = (u_int)(wp->xoff + (int)s->cx - (int)ox);
cy = wp->yoff + s->cy - oy; cy = (u_int)(wp->yoff + (int)s->cy - (int)oy);
if (status_at_line(c) == 0) if (status_at_line(c) == 0)
cy += status_line_size(c); cy += status_line_size(c);

7
tmux.h
View File

@@ -1423,8 +1423,8 @@ struct layout_cell {
u_int sx; u_int sx;
u_int sy; u_int sy;
u_int xoff; int xoff;
u_int yoff; int yoff;
struct window_pane *wp; struct window_pane *wp;
struct layout_cells cells; 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 *, void layout_resize_layout(struct window *, struct layout_cell *,
enum layout_type, int, int); enum layout_type, int, int);
struct layout_cell *layout_search_by_border(struct layout_cell *, u_int, u_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, void layout_set_size(struct layout_cell *, u_int, u_int, int, int);
u_int);
void layout_make_leaf(struct layout_cell *, struct window_pane *); void layout_make_leaf(struct layout_cell *, struct window_pane *);
void layout_make_node(struct layout_cell *, enum layout_type); void layout_make_node(struct layout_cell *, enum layout_type);
void layout_fix_zindexes(struct window *, struct layout_cell *); void layout_fix_zindexes(struct window *, struct layout_cell *);

6
tty.c
View File

@@ -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) { TAILQ_FOREACH(wpl, &w->z_index, zentry) {
if (wpl == wp || ~wpl->flags & PANE_FLOATING) if (wpl == wp || ~wpl->flags & PANE_FLOATING)
continue; 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; 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; continue;
overlap++; overlap++;
if (overlap > 0) break; if (overlap > 0) break;

View File

@@ -71,7 +71,7 @@ static struct window_pane *window_pane_create(struct window *, u_int, u_int,
u_int); u_int);
static void window_pane_destroy(struct window_pane *); static void window_pane_destroy(struct window_pane *);
static void window_pane_full_size_offset(struct window_pane *wp, 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(windows, window, entry, window_cmp);
RB_GENERATE(winlinks, winlink, entry, winlink_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). * scrollbars if they were visible but not including the border(s).
*/ */
static void 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) u_int *sx, u_int *sy)
{ {
struct window *w = wp->window; struct window *w = wp->window;
@@ -1503,9 +1503,11 @@ window_pane_find_up(struct window_pane *wp)
{ {
struct window *w; struct window *w;
struct window_pane *next, *best, **list; struct window_pane *next, *best, **list;
u_int edge, left, right, end, size; int edge, left, right, end;
u_int size;
int status, found; int status, found;
u_int xoff, yoff, sx, sy; int xoff, yoff;
u_int sx, sy;
if (wp == NULL) if (wp == NULL)
return (NULL); return (NULL);
@@ -1520,25 +1522,25 @@ window_pane_find_up(struct window_pane *wp)
edge = yoff; edge = yoff;
if (status == PANE_STATUS_TOP) { if (status == PANE_STATUS_TOP) {
if (edge == 1) if (edge == 1)
edge = w->sy + 1; edge = (int)w->sy + 1;
} else if (status == PANE_STATUS_BOTTOM) { } else if (status == PANE_STATUS_BOTTOM) {
if (edge == 0) if (edge == 0)
edge = w->sy; edge = (int)w->sy;
} else { } else {
if (edge == 0) if (edge == 0)
edge = w->sy + 1; edge = (int)w->sy + 1;
} }
left = xoff; left = xoff;
right = xoff + sx; right = xoff + (int)sx;
TAILQ_FOREACH(next, &w->panes, entry) { TAILQ_FOREACH(next, &w->panes, entry) {
window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy); window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy);
if (next == wp) if (next == wp)
continue; continue;
if (yoff + sy + 1 != edge) if (yoff + (int)sy + 1 != edge)
continue; continue;
end = xoff + sx - 1; end = xoff + (int)sx - 1;
found = 0; found = 0;
if (xoff < left && end > right) if (xoff < left && end > right)
@@ -1564,9 +1566,11 @@ window_pane_find_down(struct window_pane *wp)
{ {
struct window *w; struct window *w;
struct window_pane *next, *best, **list; struct window_pane *next, *best, **list;
u_int edge, left, right, end, size; int edge, left, right, end;
u_int size;
int status, found; int status, found;
u_int xoff, yoff, sx, sy; int xoff, yoff;
u_int sx, sy;
if (wp == NULL) if (wp == NULL)
return (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); 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 (status == PANE_STATUS_TOP) {
if (edge >= w->sy) if (edge >= (int)w->sy)
edge = 1; edge = 1;
} else if (status == PANE_STATUS_BOTTOM) { } else if (status == PANE_STATUS_BOTTOM) {
if (edge >= w->sy - 1) if (edge >= (int)w->sy - 1)
edge = 0; edge = 0;
} else { } else {
if (edge >= w->sy) if (edge >= (int)w->sy)
edge = 0; edge = 0;
} }
left = wp->xoff; left = wp->xoff;
right = wp->xoff + wp->sx; right = wp->xoff + (int)wp->sx;
TAILQ_FOREACH(next, &w->panes, entry) { TAILQ_FOREACH(next, &w->panes, entry) {
window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy); window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy);
@@ -1599,7 +1603,7 @@ window_pane_find_down(struct window_pane *wp)
continue; continue;
if (yoff != edge) if (yoff != edge)
continue; continue;
end = xoff + sx - 1; end = xoff + (int)sx - 1;
found = 0; found = 0;
if (xoff < left && end > right) if (xoff < left && end > right)
@@ -1625,9 +1629,11 @@ window_pane_find_left(struct window_pane *wp)
{ {
struct window *w; struct window *w;
struct window_pane *next, *best, **list; struct window_pane *next, *best, **list;
u_int edge, top, bottom, end, size; int edge, top, bottom, end;
u_int size;
int found; int found;
u_int xoff, yoff, sx, sy; int xoff, yoff;
u_int sx, sy;
if (wp == NULL) if (wp == NULL)
return (NULL); return (NULL);
@@ -1640,18 +1646,18 @@ window_pane_find_left(struct window_pane *wp)
edge = xoff; edge = xoff;
if (edge == 0) if (edge == 0)
edge = w->sx + 1; edge = (int)w->sx + 1;
top = yoff; top = yoff;
bottom = yoff + sy; bottom = yoff + (int)sy;
TAILQ_FOREACH(next, &w->panes, entry) { TAILQ_FOREACH(next, &w->panes, entry) {
window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy); window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy);
if (next == wp) if (next == wp)
continue; continue;
if (xoff + sx + 1 != edge) if (xoff + (int)sx + 1 != edge)
continue; continue;
end = yoff + sy - 1; end = yoff + (int)sy - 1;
found = 0; found = 0;
if (yoff < top && end > bottom) if (yoff < top && end > bottom)
@@ -1677,9 +1683,11 @@ window_pane_find_right(struct window_pane *wp)
{ {
struct window *w; struct window *w;
struct window_pane *next, *best, **list; struct window_pane *next, *best, **list;
u_int edge, top, bottom, end, size; int edge, top, bottom, end;
u_int size;
int found; int found;
u_int xoff, yoff, sx, sy; int xoff, yoff;
u_int sx, sy;
if (wp == NULL) if (wp == NULL)
return (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); window_pane_full_size_offset(wp, &xoff, &yoff, &sx, &sy);
edge = xoff + sx + 1; edge = xoff + (int)sx + 1;
if (edge >= w->sx) if (edge >= (int)w->sx)
edge = 0; edge = 0;
top = wp->yoff; top = wp->yoff;
bottom = wp->yoff + wp->sy; bottom = wp->yoff + (int)wp->sy;
TAILQ_FOREACH(next, &w->panes, entry) { TAILQ_FOREACH(next, &w->panes, entry) {
window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy); window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy);
@@ -1703,7 +1711,7 @@ window_pane_find_right(struct window_pane *wp)
continue; continue;
if (xoff != edge) if (xoff != edge)
continue; continue;
end = yoff + sy - 1; end = yoff + (int)sy - 1;
found = 0; found = 0;
if (yoff < top && end > bottom) if (yoff < top && end > bottom)