Skip to content

Commit ca00db0

Browse files
committed
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
2 parents de15bdb + d306f3d commit ca00db0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ extern const char *pager_program;
14981498
extern int pager_in_use(void);
14991499
extern int pager_use_color;
15001500
extern int term_columns(void);
1501-
extern int decimal_width(int);
1501+
extern int decimal_width(uintmax_t);
15021502
extern int check_pager_config(const char *cmd);
15031503

15041504
extern const char *editor_program;

pager.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ int term_columns(void)
133133
/*
134134
* How many columns do we need to show this number in decimal?
135135
*/
136-
int decimal_width(int number)
136+
int decimal_width(uintmax_t number)
137137
{
138-
int i, width;
138+
int width;
139139

140-
for (width = 1, i = 10; i <= number; width++)
141-
i *= 10;
140+
for (width = 1; number >= 10; width++)
141+
number /= 10;
142142
return width;
143143
}
144144

0 commit comments

Comments
 (0)