From 5eaa0a6cd8ecc90dee0ca28840d293b14e5d9de0 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Thu, 14 Apr 2016 12:35:57 -0700 Subject: [PATCH] Fix soft-padding available columns computation. If arrow_cursor is set, it's possible that COLS < offset. Compute avail_cols, floored at 0, and use that instead. --- muttlib.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/muttlib.c b/muttlib.c index fb485c7be..9096590ec 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1321,16 +1321,17 @@ void mutt_FormatString (char *dest, /* output buffer */ else if (soft && pad < 0) { int offset = ((flags & M_FORMAT_ARROWCURSOR) && option (OPTARROWCURSOR)) ? 3 : 0; + int avail_cols = (COLS > offset) ? (COLS - offset) : 0; /* \0-terminate dest for length computation in mutt_wstr_trunc() */ *wptr = 0; /* make sure right part is at most as wide as display */ - len = mutt_wstr_trunc (buf, destlen, COLS-offset, &wid); + len = mutt_wstr_trunc (buf, destlen, avail_cols, &wid); /* truncate left so that right part fits completely in */ - wlen = mutt_wstr_trunc (dest, destlen - len, COLS - wid - offset, &col); + wlen = mutt_wstr_trunc (dest, destlen - len, avail_cols - wid, &col); wptr = dest + wlen; /* Multi-column characters may be truncated in the middle. * Add spacing so the right hand side lines up. */ - while ((col + wid < COLS - offset) && (wlen + len < destlen)) + while ((col + wid < avail_cols) && (wlen + len < destlen)) { *wptr++ = ' '; wlen++; -- 2.40.0