Some `int` loop counters trigger -Wsign-comparison warnings. Use `size_t` loop counters. Signed-off-by: Zejun Zhao <jelly.zhao.42@xxxxxxxxx> --- apply.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/apply.c b/apply.c index 72464fb6c2..585f534732 100644 --- a/apply.c +++ b/apply.c @@ -1371,12 +1371,11 @@ int parse_git_diff_header(struct strbuf *root, { "index ", gitdiff_index }, { "", gitdiff_unrecognized }, }; - int i; len = linelen(line, size); if (!len || line[len-1] != '\n') break; - for (i = 0; i < ARRAY_SIZE(optable); i++) { + for (size_t i = 0; i < ARRAY_SIZE(optable); i++) { const struct opentry *p = optable + i; int oplen = strlen(p->str); int res; @@ -2097,7 +2096,6 @@ static void add_name_limit(struct apply_state *state, static int use_patch(struct apply_state *state, struct patch *p) { const char *pathname = p->new_name ? p->new_name : p->old_name; - int i; /* Paths outside are not touched regardless of "--include" */ if (state->prefix && *state->prefix) { @@ -2107,7 +2105,7 @@ static int use_patch(struct apply_state *state, struct patch *p) } /* See if it matches any of exclude/include rule */ - for (i = 0; i < state->limit_by_name.nr; i++) { + for (size_t i = 0; i < state->limit_by_name.nr; i++) { struct string_list_item *it = &state->limit_by_name.items[i]; if (!wildmatch(it->string, pathname, 0)) return (it->util != NULL); @@ -2183,8 +2181,7 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long si "Files ", NULL, }; - int i; - for (i = 0; binhdr[i]; i++) { + for (size_t i = 0; binhdr[i]; i++) { size_t len = strlen(binhdr[i]); if (len < size - hd && !memcmp(binhdr[i], buffer + hd, len)) { @@ -2320,7 +2317,7 @@ static void update_pre_post_images(struct image *preimage, { struct image fixed_preimage = IMAGE_INIT; size_t insert_pos = 0; - int i, reduced; + int reduced; size_t ctx; const char *fixed; @@ -2330,7 +2327,7 @@ static void update_pre_post_images(struct image *preimage, * free "oldlines". */ image_prepare(&fixed_preimage, buf, len, 1); - for (i = 0; i < fixed_preimage.line_nr; i++) + for (size_t i = 0; i < fixed_preimage.line_nr; i++) fixed_preimage.line[i].flag = preimage->line[i].flag; image_clear(preimage); *preimage = fixed_preimage; @@ -2339,7 +2336,7 @@ static void update_pre_post_images(struct image *preimage, /* * Adjust the common context lines in postimage. */ - for (i = reduced = ctx = 0; i < postimage->line_nr; i++) { + for (size_t i = reduced = ctx = 0; i < postimage->line_nr; i++) { size_t l_len = postimage->line[i].len; if (!(postimage->line[i].flag & LINE_COMMON)) { @@ -2419,9 +2416,9 @@ static int line_by_line_fuzzy_match(struct image *img, struct image *postimage, unsigned long current, int current_lno, - int preimage_limit) + size_t preimage_limit) { - int i; + size_t i; size_t imgoff = 0; size_t preoff = 0; size_t extra_chars; @@ -2488,7 +2485,7 @@ static int match_fragment(struct apply_state *state, unsigned ws_rule, int match_beginning, int match_end) { - int i; + size_t i; const char *orig, *target; struct strbuf fixed = STRBUF_INIT; char *fixed_buf; @@ -2665,12 +2662,11 @@ static int match_fragment(struct apply_state *state, for ( ; i < preimage->line_nr; i++) { size_t fixstart = fixed.len; /* start of the fixed preimage */ size_t oldlen = preimage->line[i].len; - int j; /* Try fixing the line in the preimage */ ws_fix_copy(&fixed, orig, oldlen, ws_rule, NULL); - for (j = fixstart; j < fixed.len; j++) { + for (size_t j = fixstart; j < fixed.len; j++) { if (!isspace(fixed.buf[j])) { ret = 0; goto out; @@ -2800,7 +2796,7 @@ static void update_image(struct apply_state *state, * remove the copy of preimage at offset in img * and replace it with postimage */ - int i, nr; + int nr; size_t remove_count, insert_count, applied_at = 0; size_t result_alloc; char *result; @@ -2819,11 +2815,11 @@ static void update_image(struct apply_state *state, if (preimage_limit > img->line_nr - applied_pos) preimage_limit = img->line_nr - applied_pos; - for (i = 0; i < applied_pos; i++) + for (size_t i = 0; i < applied_pos; i++) applied_at += img->line[i].len; remove_count = 0; - for (i = 0; i < preimage_limit; i++) + for (size_t i = 0; i < preimage_limit; i++) remove_count += img->line[applied_pos + i].len; insert_count = postimage->buf.len; @@ -2852,7 +2848,7 @@ static void update_image(struct apply_state *state, img->line_nr - (applied_pos + preimage_limit)); COPY_ARRAY(img->line + applied_pos, postimage->line, postimage->line_nr); if (!state->allow_overlap) - for (i = 0; i < postimage->line_nr; i++) + for (size_t i = 0; i < postimage->line_nr; i++) img->line[applied_pos + i].flag |= LINE_PATCHED; img->line_nr = nr; } -- 2.43.0