Skip to content

Commit bc32d34

Browse files
committed
Merge branch 'jk/maint-diffstat-overflow'
* jk/maint-diffstat-overflow: diff: use large integers for diffstat calculations
2 parents 779f946 + 0974c11 commit bc32d34

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

diff.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ struct diffstat_t {
953953
unsigned is_unmerged:1;
954954
unsigned is_binary:1;
955955
unsigned is_renamed:1;
956-
unsigned int added, deleted;
956+
uintmax_t added, deleted;
957957
} **files;
958958
};
959959

@@ -1045,7 +1045,7 @@ static void fill_print_name(struct diffstat_file *file)
10451045
static void show_stats(struct diffstat_t *data, struct diff_options *options)
10461046
{
10471047
int i, len, add, del, adds = 0, dels = 0;
1048-
int max_change = 0, max_len = 0;
1048+
uintmax_t max_change = 0, max_len = 0;
10491049
int total_files = data->nr;
10501050
int width, name_width;
10511051
const char *reset, *set, *add_c, *del_c;
@@ -1074,7 +1074,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
10741074

10751075
for (i = 0; i < data->nr; i++) {
10761076
struct diffstat_file *file = data->files[i];
1077-
int change = file->added + file->deleted;
1077+
uintmax_t change = file->added + file->deleted;
10781078
fill_print_name(file);
10791079
len = strlen(file->print_name);
10801080
if (max_len < len)
@@ -1102,8 +1102,8 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
11021102
for (i = 0; i < data->nr; i++) {
11031103
const char *prefix = "";
11041104
char *name = data->files[i]->print_name;
1105-
int added = data->files[i]->added;
1106-
int deleted = data->files[i]->deleted;
1105+
uintmax_t added = data->files[i]->added;
1106+
uintmax_t deleted = data->files[i]->deleted;
11071107
int name_len;
11081108

11091109
/*
@@ -1124,9 +1124,11 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
11241124
if (data->files[i]->is_binary) {
11251125
show_name(options->file, prefix, name, len);
11261126
fprintf(options->file, " Bin ");
1127-
fprintf(options->file, "%s%d%s", del_c, deleted, reset);
1127+
fprintf(options->file, "%s%"PRIuMAX"%s",
1128+
del_c, deleted, reset);
11281129
fprintf(options->file, " -> ");
1129-
fprintf(options->file, "%s%d%s", add_c, added, reset);
1130+
fprintf(options->file, "%s%"PRIuMAX"%s",
1131+
add_c, added, reset);
11301132
fprintf(options->file, " bytes");
11311133
fprintf(options->file, "\n");
11321134
continue;
@@ -1155,7 +1157,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
11551157
del = scale_linear(del, width, max_change);
11561158
}
11571159
show_name(options->file, prefix, name, len);
1158-
fprintf(options->file, "%5d%s", added + deleted,
1160+
fprintf(options->file, "%5"PRIuMAX"%s", added + deleted,
11591161
added + deleted ? " " : "");
11601162
show_graph(options->file, '+', add, add_c, reset);
11611163
show_graph(options->file, '-', del, del_c, reset);
@@ -1205,7 +1207,8 @@ static void show_numstat(struct diffstat_t *data, struct diff_options *options)
12051207
fprintf(options->file, "-\t-\t");
12061208
else
12071209
fprintf(options->file,
1208-
"%d\t%d\t", file->added, file->deleted);
1210+
"%"PRIuMAX"\t%"PRIuMAX"\t",
1211+
file->added, file->deleted);
12091212
if (options->line_termination) {
12101213
fill_print_name(file);
12111214
if (!file->is_renamed)

0 commit comments

Comments
 (0)