This fixes two problems in the current version:

1. The expando is only truncated if the destination size is bigger
than the limit, not the columns.

2. The column in incremented by the length of the whole expando, not
the truncated version.

Both of these cause problems for soft-fill "%*".  If the entire
buffer is filled up by a very large expando value, the soft fill will
never be reached.  To make that much less likely, don't add the whole
huge value, only the part that fits on the screen.

Additionally, the col value could become bigger than the cols,
creating bugs in other places that pass "cols - col" to truncation.

Some parts of Mutt use mutt_FormatString() to expand program
invocation or other data strings, passing a bogus value of
columns. The next few commits will clean up those issues.
---
 muttlib.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/muttlib.c b/muttlib.c
index bcd3f50e..edc75619 100644
--- a/muttlib.c
+++ b/muttlib.c
@@ -1892,13 +1892,12 @@ void mutt_FormatString(char *dest,             /* 
output buffer */
               *p = '_';
         }
 
-        if ((len = mutt_strlen(buf)) + wlen > destlen)
-          len = mutt_wstr_trunc(buf, destlen - wlen, cols - col, NULL);
+        len = mutt_wstr_trunc(buf, destlen - wlen, cols - col, &wid);
 
         memcpy(wptr, buf, len);
         wptr += len;
         wlen += len;
-        col += mutt_strwidth(buf);
+        col += wid;
       }
     }
     else if (*src == '\\')
-- 
2.56.1

Reply via email to