The "commit-graph.c" file has a bunch of sign comparison warnings: - There are a bunch of variables that are declared as signed integers even though they are used to count entities, like for example `num_commit_graphs_before` and `num_commit_graphs_after`. - There are several cases where we use signed loop variables to iterate through an unsigned entity count. - In `write_graph_chunk_base_1()` we count how many chunks we have written in total. But while the value represents a positive quantity, we still return a signed integer that we then later compare with unsigned values. - The bloom settings hash version is being assigned `-1` even though it's an unsigned value. This is used to indicate an unspecified value and relies on 1's complement. Fix all of these cases by either using the proper variable type or by adding casts as required. Signed-off-by: Patrick Steinhardt <ps@xxxxxx> --- commit-graph.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index ad3f084dd4..443177ffd3 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1,5 +1,4 @@ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "git-compat-util.h" #include "config.h" @@ -569,7 +568,7 @@ static void validate_mixed_bloom_settings(struct commit_graph *g) static int add_graph_to_chain(struct commit_graph *g, struct commit_graph *chain, struct object_id *oids, - int n) + size_t n) { struct commit_graph *cur_g = chain; @@ -622,7 +621,7 @@ int open_commit_graph_chain(const char *chain_file, close(*fd); return 0; } - if (st->st_size < the_hash_algo->hexsz) { + if (st->st_size < (ssize_t) the_hash_algo->hexsz) { close(*fd); if (!st->st_size) { /* treat empty files the same as missing */ @@ -643,15 +642,16 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r, struct commit_graph *graph_chain = NULL; struct strbuf line = STRBUF_INIT; struct object_id *oids; - int i = 0, valid = 1, count; + int valid = 1; FILE *fp = xfdopen(fd, "r"); + size_t count; count = st->st_size / (the_hash_algo->hexsz + 1); CALLOC_ARRAY(oids, count); odb_prepare_alternates(r->objects); - for (i = 0; i < count; i++) { + for (size_t i = 0; i < count; i++) { struct odb_source *source; if (strbuf_getline_lf(&line, fp) == EOF) @@ -1145,12 +1145,12 @@ struct write_commit_graph_context { int num_generation_data_overflows; unsigned long approx_nr_objects; struct progress *progress; - int progress_done; + uint64_t progress_done; uint64_t progress_cnt; char *base_graph_name; - int num_commit_graphs_before; - int num_commit_graphs_after; + size_t num_commit_graphs_before; + size_t num_commit_graphs_after; char **commit_graph_filenames_before; char **commit_graph_filenames_after; char **commit_graph_hash_after; @@ -1181,7 +1181,7 @@ static int write_graph_chunk_fanout(struct hashfile *f, void *data) { struct write_commit_graph_context *ctx = data; - int i, count = 0; + size_t i, count = 0; struct commit **list = ctx->commits.list; /* @@ -1209,7 +1209,8 @@ static int write_graph_chunk_oids(struct hashfile *f, { struct write_commit_graph_context *ctx = data; struct commit **list = ctx->commits.list; - int count; + size_t count; + for (count = 0; count < ctx->commits.nr; count++, list++) { display_progress(ctx->progress, ++ctx->progress_cnt); hashwrite(f, (*list)->object.oid.hash, the_hash_algo->rawsz); @@ -1331,9 +1332,9 @@ static int write_graph_chunk_generation_data(struct hashfile *f, void *data) { struct write_commit_graph_context *ctx = data; - int i, num_generation_data_overflows = 0; + int num_generation_data_overflows = 0; - for (i = 0; i < ctx->commits.nr; i++) { + for (size_t i = 0; i < ctx->commits.nr; i++) { struct commit *c = ctx->commits.list[i]; timestamp_t offset; repo_parse_commit(ctx->r, c); @@ -1355,8 +1356,8 @@ static int write_graph_chunk_generation_data_overflow(struct hashfile *f, void *data) { struct write_commit_graph_context *ctx = data; - int i; - for (i = 0; i < ctx->commits.nr; i++) { + + for (size_t i = 0; i < ctx->commits.nr; i++) { struct commit *c = ctx->commits.list[i]; timestamp_t offset = commit_graph_data_at(c)->generation - c->date; display_progress(ctx->progress, ++ctx->progress_cnt); @@ -1526,7 +1527,7 @@ static void add_missing_parents(struct write_commit_graph_context *ctx, struct c static void close_reachable(struct write_commit_graph_context *ctx) { - int i; + size_t i; struct commit *commit; enum commit_graph_split_flags flags = ctx->opts ? ctx->opts->split_flags : COMMIT_GRAPH_SPLIT_UNSPECIFIED; @@ -1620,10 +1621,9 @@ static void compute_reachable_generation_numbers( struct compute_generation_info *info, int generation_version) { - int i; struct commit_list *list = NULL; - for (i = 0; i < info->commits->nr; i++) { + for (size_t i = 0; i < info->commits->nr; i++) { struct commit *c = info->commits->list[i]; timestamp_t gen; repo_parse_commit(info->r, c); @@ -1714,7 +1714,7 @@ static void set_generation_v2(struct commit *c, timestamp_t t, static void compute_generation_numbers(struct write_commit_graph_context *ctx) { - int i; + size_t i; struct compute_generation_info info = { .r = ctx->r, .commits = &ctx->commits, @@ -1793,10 +1793,10 @@ static void trace2_bloom_filter_write_statistics(struct write_commit_graph_conte static void compute_bloom_filters(struct write_commit_graph_context *ctx) { - int i; + size_t i; struct progress *progress = NULL; struct commit **sorted_commits; - int max_new_filters; + size_t max_new_filters; init_bloom_filters(); @@ -1814,7 +1814,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx) QSORT(sorted_commits, ctx->commits.nr, commit_gen_cmp); max_new_filters = ctx->opts && ctx->opts->max_new_filters >= 0 ? - ctx->opts->max_new_filters : ctx->commits.nr; + (size_t) ctx->opts->max_new_filters : ctx->commits.nr; for (i = 0; i < ctx->commits.nr; i++) { enum bloom_filter_computed computed = 0; @@ -2017,10 +2017,10 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx) stop_progress(&ctx->progress); } -static int write_graph_chunk_base_1(struct hashfile *f, - struct commit_graph *g) +static size_t write_graph_chunk_base_1(struct hashfile *f, + struct commit_graph *g) { - int num = 0; + size_t num = 0; if (!g) return 0; @@ -2034,7 +2034,7 @@ static int write_graph_chunk_base(struct hashfile *f, void *data) { struct write_commit_graph_context *ctx = data; - int num = write_graph_chunk_base_1(f, ctx->new_base_graph); + size_t num = write_graph_chunk_base_1(f, ctx->new_base_graph); if (num != ctx->num_commit_graphs_after - 1) { error(_("failed to write correct number of base graph ids")); @@ -2480,7 +2480,7 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx) if (stat(path.buf, &st) < 0) continue; - if (st.st_mtime > expire_time) + if ((unsigned) st.st_mtime > expire_time) continue; if (path.len < 6 || strcmp(path.buf + path.len - 6, ".graph")) continue; @@ -2576,7 +2576,7 @@ int write_commit_graph(struct odb_source *source, ctx.changed_paths = 1; /* don't propagate the hash_version unless unspecified */ - if (bloom_settings.hash_version == -1) + if (bloom_settings.hash_version == (unsigned) -1) bloom_settings.hash_version = g->bloom_filter_settings->hash_version; bloom_settings.bits_per_entry = g->bloom_filter_settings->bits_per_entry; bloom_settings.num_hashes = g->bloom_filter_settings->num_hashes; -- 2.50.1.723.g3e08bea96f.dirty