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.
/* 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