global: trivial conversions to fix -Wsign-compare warnings

We have a bunch of loops which iterate up to an unsigned boundary using
a signed index, which generates warnigs because we compare a signed and
unsigned value in the loop condition. Address these sites for trivial
cases and enable `-Wsign-compare` warnings for these code units.

This patch only adapts those code units where we can drop the
`DISABLE_SIGN_COMPARE_WARNINGS` macro in the same step.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2024-12-06 11:27:24 +01:00
committed by Junio C Hamano
parent 25435e4ad8
commit 80c9e70ebe
55 changed files with 105 additions and 238 deletions

7
hex.c
View File

@ -1,5 +1,4 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
#include "hash.h"
@ -8,8 +7,7 @@
static int get_hash_hex_algop(const char *hex, unsigned char *hash,
const struct git_hash_algo *algop)
{
int i;
for (i = 0; i < algop->rawsz; i++) {
for (size_t i = 0; i < algop->rawsz; i++) {
int val = hex2chr(hex);
if (val < 0)
return -1;
@ -84,7 +82,6 @@ char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash,
{
static const char hex[] = "0123456789abcdef";
char *buf = buffer;
int i;
/*
* Our struct object_id has been memset to 0, so default to printing
@ -93,7 +90,7 @@ char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash,
if (algop == &hash_algos[0])
algop = the_hash_algo;
for (i = 0; i < algop->rawsz; i++) {
for (size_t i = 0; i < algop->rawsz; i++) {
unsigned int val = *hash++;
*buf++ = hex[val >> 4];
*buf++ = hex[val & 0xf];