connect: address -Wsign-compare warnings

Most of the warnings were about loop variables being declared as ints with a condition using a size_t, whereby switching the variable to size_t fixes the warning. One other case was comparing the result of strlen to an int passed as an argument, which turns out could just as well be passed as a size_t, albeit trickling to other functions. Signed-off-by: Mike Hommey <mh@glandium.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mike Hommey committed Jan 17, 2025 at 16:49 UTC 49b299215dd779b781c5a39af85a5acb6294acbd
1 file changed +11 -12
connect.c
+11 -12
@@ -1,5 +1,4 @@
1 #define USE_THE_REPOSITORY_VARIABLE
2 -#define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
4 #include "config.h"
@@ -77,7 +76,7 @@ static NORETURN void die_initial_contact(int unexpected)
76 /* Checks if the server supports the capability 'c' */
77 int server_supports_v2(const char *c)
78 {
80 - int i;
79 + size_t i;
80
81 for (i = 0; i < server_capabilities_v2.nr; i++) {
82 const char *out;
@@ -96,7 +95,7 @@ void ensure_server_supports_v2(const char *c)
95
96 int server_feature_v2(const char *c, const char **v)
97 {
99 - int i;
98 + size_t i;
99
100 for (i = 0; i < server_capabilities_v2.nr; i++) {
101 const char *out;
@@ -112,7 +111,7 @@ int server_feature_v2(const char *c, const char **v)
111 int server_supports_feature(const char *c, const char *feature,
112 int die_on_error)
113 {
115 - int i;
114 + size_t i;
115
116 for (i = 0; i < server_capabilities_v2.nr; i++) {
117 const char *out;
@@ -232,12 +231,12 @@ static void annotate_refs_with_symref_info(struct ref *ref)
231 string_list_clear(&symref, 0);
232 }
233
235 -static void process_capabilities(struct packet_reader *reader, int *linelen)
234 +static void process_capabilities(struct packet_reader *reader, size_t *linelen)
235 {
236 const char *feat_val;
237 size_t feat_len;
238 const char *line = reader->line;
240 - int nul_location = strlen(line);
239 + size_t nul_location = strlen(line);
240 if (nul_location == *linelen)
241 return;
242 server_capabilities_v1 = xstrdup(line + nul_location + 1);
@@ -271,14 +270,14 @@ static int process_dummy_ref(const struct packet_reader *reader)
270 !strcmp(name, "capabilities^{}");
271 }
272
274 -static void check_no_capabilities(const char *line, int len)
273 +static void check_no_capabilities(const char *line, size_t len)
274 {
275 if (strlen(line) != len)
276 warning(_("ignoring capabilities after first line '%s'"),
277 line + strlen(line));
278 }
279
281 -static int process_ref(const struct packet_reader *reader, int len,
280 +static int process_ref(const struct packet_reader *reader, size_t len,
281 struct ref ***list, unsigned int flags,
282 struct oid_array *extra_have)
283 {
@@ -306,7 +305,7 @@ static int process_ref(const struct packet_reader *reader, int len,
305 return 1;
306 }
307
309 -static int process_shallow(const struct packet_reader *reader, int len,
308 +static int process_shallow(const struct packet_reader *reader, size_t len,
309 struct oid_array *shallow_points)
310 {
311 const char *line = reader->line;
@@ -341,7 +340,7 @@ struct ref **get_remote_heads(struct packet_reader *reader,
340 struct oid_array *shallow_points)
341 {
342 struct ref **orig_list = list;
344 - int len = 0;
343 + size_t len = 0;
344 enum get_remote_heads_state state = EXPECTING_FIRST_REF;
345
346 *list = NULL;
@@ -394,7 +393,7 @@ static int process_ref_v2(struct packet_reader *reader, struct ref ***list,
393 const char **unborn_head_target)
394 {
395 int ret = 1;
397 - int i = 0;
396 + size_t i = 0;
397 struct object_id old_oid;
398 struct ref *ref;
399 struct string_list line_sections = STRING_LIST_INIT_DUP;
@@ -552,7 +551,7 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
551 const struct string_list *server_options,
552 int stateless_rpc)
553 {
555 - int i;
554 + size_t i;
555 struct strvec *ref_prefixes = transport_options ?
556 &transport_options->ref_prefixes : NULL;
557 const char **unborn_head_target = transport_options ?