From: Kevin McCarthy Date: Thu, 14 Apr 2016 19:35:53 +0000 (-0700) Subject: Fix right justify buffer-truncated pad calculation in mutt_FormatString() X-Git-Tag: neomutt-20160822~171 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b847879294e384b1442d5ff980a165d5e0faa746;p=neomutt Fix right justify buffer-truncated pad calculation in mutt_FormatString() Vincent Lefèvre noted that the computation had implementation defined behavior and was potentially incorrect. Change to make sure the subtraction won't lead to a wrap-around, and set pad to 0 in that case. --- diff --git a/muttlib.c b/muttlib.c index 309f1bfed..fb485c7be 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1297,7 +1297,7 @@ void mutt_FormatString (char *dest, /* output buffer */ /* try to consume as many columns as we can, if we don't have * memory for that, use as much memory as possible */ if (wlen + (pad * pl) + len > destlen) - pad = ((signed)(destlen - wlen - len)) / pl; + pad = (destlen > wlen + len) ? ((destlen - wlen - len) / pl) : 0; else { /* Add pre-spacing to make multi-column pad characters and