From e2f34de7de4ed14024e13486ab48f04884e2a7b2 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Wed, 8 Jan 2020 14:40:53 +0000 Subject: Do not hang in format_trim_* on invalid UTF-8 characters. --- usr.bin/tmux/format-draw.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'usr.bin/tmux/format-draw.c') diff --git a/usr.bin/tmux/format-draw.c b/usr.bin/tmux/format-draw.c index 441bfe7fc4e..c4264cde02a 100644 --- a/usr.bin/tmux/format-draw.c +++ b/usr.bin/tmux/format-draw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format-draw.c,v 1.13 2019/09/15 21:42:57 nicm Exp $ */ +/* $OpenBSD: format-draw.c,v 1.14 2020/01/08 14:40:52 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott @@ -849,8 +849,10 @@ format_trim_left(const char *expanded, u_int limit) out += ud.size; } width += ud.width; - } else + } else { cp -= ud.have; + cp++; + } } else if (*cp > 0x1f && *cp < 0x7f) { if (width + 1 <= limit) *out++ = *cp; @@ -896,8 +898,10 @@ format_trim_right(const char *expanded, u_int limit) out += ud.size; } width += ud.width; - } else + } else { cp -= ud.have; + cp++; + } } else if (*cp > 0x1f && *cp < 0x7f) { if (width >= skip) *out++ = *cp; -- cgit v1.2.3