1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-11-04 16:45:07 -05:00

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

View File

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