hash: fix "-Wsign-compare" warnings
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>
Patrick Steinhardt committed
Mar 10, 2025 at 08:13 UTC
8ca9fa60a63c97bb9397f5de294aef53df90e7a0
2 files changed
+5
-9
hash.c
+4
-8
@@ -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 "hash.h"
@@ -246,10 +245,9 @@ const char *empty_tree_oid_hex(const struct git_hash_algo *algop)
245
246
int hash_algo_by_name(const char *name)
247
{
249
- int i;
248
if (!name)
249
return GIT_HASH_UNKNOWN;
252
- for (i = 1; i < GIT_HASH_NALGOS; i++)
250
+ for (size_t i = 1; i < GIT_HASH_NALGOS; i++)
251
if (!strcmp(name, hash_algos[i].name))
252
return i;
253
return GIT_HASH_UNKNOWN;
@@ -257,17 +255,15 @@ int hash_algo_by_name(const char *name)
255
256
int hash_algo_by_id(uint32_t format_id)
257
{
260
- int i;
261
- for (i = 1; i < GIT_HASH_NALGOS; i++)
258
+ for (size_t i = 1; i < GIT_HASH_NALGOS; i++)
259
if (format_id == hash_algos[i].format_id)
260
return i;
261
return GIT_HASH_UNKNOWN;
262
}
263
267
-int hash_algo_by_length(int len)
264
+int hash_algo_by_length(size_t len)
265
{
269
- int i;
270
- for (i = 1; i < GIT_HASH_NALGOS; i++)
266
+ for (size_t i = 1; i < GIT_HASH_NALGOS; i++)
267
if (len == hash_algos[i].rawsz)
268
return i;
269
return GIT_HASH_UNKNOWN;
hash.h
+1
-1
@@ -325,7 +325,7 @@ int hash_algo_by_name(const char *name);
325
/* Identical, except based on the format ID. */
326
int hash_algo_by_id(uint32_t format_id);
327
/* Identical, except based on the length. */
328
-int hash_algo_by_length(int len);
328
+int hash_algo_by_length(size_t len);
329
/* Identical, except for a pointer to struct git_hash_algo. */
330
static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
331
{