object-file: fix -Wsign-compare warnings

There are some trivial -Wsign-compare warnings in "object-file.c". Fix them and drop the preprocessor define that disables those warnings. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 17, 2025 at 06:56 UTC 80e7f52299619575cb48522a4ca40427e2231dc6
1 file changed +6 -9
object-file.c
+6 -9
@@ -8,7 +8,6 @@
8 */
9
10 #define USE_THE_REPOSITORY_VARIABLE
11 -#define DISABLE_SIGN_COMPARE_WARNINGS
11
12 #include "git-compat-util.h"
13 #include "bulk-checkin.h"
@@ -44,8 +43,7 @@ static int get_conv_flags(unsigned flags)
43
44 static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
45 {
47 - int i;
48 - for (i = 0; i < the_hash_algo->rawsz; i++) {
46 + for (size_t i = 0; i < the_hash_algo->rawsz; i++) {
47 static char hex[] = "0123456789abcdef";
48 unsigned int val = oid->hash[i];
49 strbuf_addch(buf, hex[val >> 4]);
@@ -327,9 +325,8 @@ static void *unpack_loose_rest(git_zstream *stream,
325 void *buffer, unsigned long size,
326 const struct object_id *oid)
327 {
330 - int bytes = strlen(buffer) + 1;
328 + size_t bytes = strlen(buffer) + 1, n;
329 unsigned char *buf = xmallocz(size);
332 - unsigned long n;
330 int status = Z_OK;
331
332 n = stream->total_out - bytes;
@@ -596,7 +593,7 @@ static int check_collision(const char *source, const char *dest)
593 goto out;
594 }
595
599 - if (sz_a < sizeof(buf_source))
596 + if ((size_t) sz_a < sizeof(buf_source))
597 break;
598 }
599
@@ -1240,7 +1237,7 @@ static int index_core(struct index_state *istate,
1237 if (read_result < 0)
1238 ret = error_errno(_("read error while indexing %s"),
1239 path ? path : "<unknown>");
1243 - else if (read_result != size)
1240 + else if ((size_t) read_result != size)
1241 ret = error(_("short read while indexing %s"),
1242 path ? path : "<unknown>");
1243 else
@@ -1268,7 +1265,7 @@ int index_fd(struct index_state *istate, struct object_id *oid,
1265 ret = index_stream_convert_blob(istate, oid, fd, path, flags);
1266 else if (!S_ISREG(st->st_mode))
1267 ret = index_pipe(istate, oid, fd, type, path, flags);
1271 - else if (st->st_size <= repo_settings_get_big_file_threshold(the_repository) ||
1268 + else if ((st->st_size >= 0 && (size_t) st->st_size <= repo_settings_get_big_file_threshold(the_repository)) ||
1269 type != OBJ_BLOB ||
1270 (path && would_convert_to_git(istate, path)))
1271 ret = index_core(istate, oid, fd, xsize_t(st->st_size),
@@ -1472,7 +1469,7 @@ struct oidtree *odb_loose_cache(struct odb_source *source,
1469 uint32_t *bitmap;
1470
1471 if (subdir_nr < 0 ||
1475 - subdir_nr >= bitsizeof(source->loose_objects_subdir_seen))
1472 + (size_t) subdir_nr >= bitsizeof(source->loose_objects_subdir_seen))
1473 BUG("subdir_nr out of range");
1474
1475 bitmap = &source->loose_objects_subdir_seen[word_index];