]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hash: fix "-Wsign-compare" warnings
authorPatrick Steinhardt <ps@pks.im>
Mon, 10 Mar 2025 07:13:30 +0000 (08:13 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Mar 2025 20:16:20 +0000 (13:16 -0700)
There are a couple of trivial "-Wsign-compare" warnings in "hash.c". Fix
them.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
hash.c
hash.h

diff --git a/hash.c b/hash.c
index dd5ac9d0eb247f01cc9249f485c4dac25a88d21c..4d9f98f72c2fed74c8a9a9555734c43de14b440d 100644 (file)
--- a/hash.c
+++ b/hash.c
@@ -1,5 +1,4 @@
 #define USE_THE_REPOSITORY_VARIABLE
-#define DISABLE_SIGN_COMPARE_WARNINGS
 
 #include "git-compat-util.h"
 #include "hash.h"
@@ -246,10 +245,9 @@ const char *empty_tree_oid_hex(const struct git_hash_algo *algop)
 
 int hash_algo_by_name(const char *name)
 {
-       int i;
        if (!name)
                return GIT_HASH_UNKNOWN;
-       for (i = 1; i < GIT_HASH_NALGOS; i++)
+       for (size_t i = 1; i < GIT_HASH_NALGOS; i++)
                if (!strcmp(name, hash_algos[i].name))
                        return i;
        return GIT_HASH_UNKNOWN;
@@ -257,17 +255,15 @@ int hash_algo_by_name(const char *name)
 
 int hash_algo_by_id(uint32_t format_id)
 {
-       int i;
-       for (i = 1; i < GIT_HASH_NALGOS; i++)
+       for (size_t i = 1; i < GIT_HASH_NALGOS; i++)
                if (format_id == hash_algos[i].format_id)
                        return i;
        return GIT_HASH_UNKNOWN;
 }
 
-int hash_algo_by_length(int len)
+int hash_algo_by_length(size_t len)
 {
-       int i;
-       for (i = 1; i < GIT_HASH_NALGOS; i++)
+       for (size_t i = 1; i < GIT_HASH_NALGOS; i++)
                if (len == hash_algos[i].rawsz)
                        return i;
        return GIT_HASH_UNKNOWN;
diff --git a/hash.h b/hash.h
index 4367acfec5098ac1fec0c1d5c2fba6ce0acd7f5d..55d67ed83f3ed902f78cd161d2a4a8fc5ee712bb 100644 (file)
--- a/hash.h
+++ b/hash.h
@@ -325,7 +325,7 @@ int hash_algo_by_name(const char *name);
 /* Identical, except based on the format ID. */
 int hash_algo_by_id(uint32_t format_id);
 /* Identical, except based on the length. */
-int hash_algo_by_length(int len);
+int hash_algo_by_length(size_t len);
 /* Identical, except for a pointer to struct git_hash_algo. */
 static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
 {