From: Junio C Hamano Date: Wed, 18 Feb 2015 19:45:02 +0000 (-0800) Subject: Merge branch 'jk/decimal-width-for-uintmax' X-Git-Tag: v2.4.0-rc0~107 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/ca00db08da414b3f6bd9481a51fdbb4b6836719c?hp=de15bdb0583a1a65bf1bab47b7bec9bdc03f727a Merge branch 'jk/decimal-width-for-uintmax' We didn't format an integer that wouldn't fit in "int" but in "uintmax_t" correctly. * jk/decimal-width-for-uintmax: decimal_width: avoid integer overflow --- diff --git a/cache.h b/cache.h index f704af5df0..04951ddcbf 100644 --- a/cache.h +++ b/cache.h @@ -1498,7 +1498,7 @@ extern const char *pager_program; extern int pager_in_use(void); extern int pager_use_color; extern int term_columns(void); -extern int decimal_width(int); +extern int decimal_width(uintmax_t); extern int check_pager_config(const char *cmd); extern const char *editor_program; diff --git a/pager.c b/pager.c index f6e8c33192..98b26823c9 100644 --- a/pager.c +++ b/pager.c @@ -133,12 +133,12 @@ int term_columns(void) /* * How many columns do we need to show this number in decimal? */ -int decimal_width(int number) +int decimal_width(uintmax_t number) { - int i, width; + int width; - for (width = 1, i = 10; i <= number; width++) - i *= 10; + for (width = 1; number >= 10; width++) + number /= 10; return width; }