Avoid interger overflow when calculating remaining line length

When the len and cidx were changed to size_t in a8a1b093, it was
possible to have an integer overflow when a line ended right at the
edge of the terminal width.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2012-08-11 23:43:43 +10:00 committed by Dan McGee
parent 7262f4bed4
commit 8f5ee72974
1 changed files with 1 additions and 1 deletions

View File

@ -304,7 +304,7 @@ void indentprint(const char *str, unsigned short indent, unsigned short cols)
while(q < next) {
len += wcwidth(*q++);
}
if(len > (cols - cidx - 1)) {
if((len + 1) > (cols - cidx)) {
/* wrap to a newline and reindent */
printf("\n%-*s", (int)indent, "");
cidx = indent;