From b90b722a1d4be467a7a6a2e5f54ad79adbc8f269 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 12 Dec 2019 15:03:14 +0000 Subject: Do not crash in tree modes if the pane is only 1 in width, reported by KOIE Hidetaka in GitHub issue 2015. --- usr.bin/tmux/mode-tree.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'usr.bin/tmux/mode-tree.c') 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 @@ -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); -- cgit v1.2.3