summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/mode-tree.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2019-12-12 15:03:14 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2019-12-12 15:03:14 +0000
commitb90b722a1d4be467a7a6a2e5f54ad79adbc8f269 (patch)
tree3c65b6b63e1f666bb6bd19f160e297a13dbedf9c /usr.bin/tmux/mode-tree.c
parent39283bee2944cc19cfe0216796b0a51ee8628e1f (diff)
Do not crash in tree modes if the pane is only 1 in width, reported by
KOIE Hidetaka in GitHub issue 2015.
Diffstat (limited to 'usr.bin/tmux/mode-tree.c')
-rw-r--r--usr.bin/tmux/mode-tree.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/usr.bin/tmux/mode-tree.c b/usr.bin/tmux/mode-tree.c
index 3319183dd37..60017a7f69e 100644
--- a/usr.bin/tmux/mode-tree.c
+++ b/usr.bin/tmux/mode-tree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mode-tree.c,v 1.36 2019/08/16 11:49:12 nicm Exp $ */
+/* $OpenBSD: mode-tree.c,v 1.37 2019/12/12 15:03:13 nicm Exp $ */
/*
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -598,6 +598,8 @@ mode_tree_draw(struct mode_tree_data *mtd)
xasprintf(&text, "%-*s%s%s%s: ", keylen, key, start, mti->name,
tag);
width = utf8_cstrwidth(text);
+ if (width > w)
+ width = w;
free(start);
if (mti->tagged) {
@@ -607,11 +609,11 @@ mode_tree_draw(struct mode_tree_data *mtd)
if (i != mtd->current) {
screen_write_clearendofline(&ctx, 8);
- screen_write_puts(&ctx, &gc0, "%s", text);
+ screen_write_nputs(&ctx, w, &gc0, "%s", text);
format_draw(&ctx, &gc0, w - width, mti->text, NULL);
} else {
screen_write_clearendofline(&ctx, gc.bg);
- screen_write_puts(&ctx, &gc, "%s", text);
+ screen_write_nputs(&ctx, w, &gc, "%s", text);
format_draw(&ctx, &gc, w - width, mti->text, NULL);
}
free(text);