Skip to content

Commit 87318f2

Browse files
pks-tgitster
authored andcommitted
gpg-interface: address -Wsign-comparison warnings
There are a couple of -Wsign-comparison warnings in "gpg-interface.c". Most of them are trivial and simply using signed integers to loop towards an upper unsigned bound. But in `parse_signed_buffer()` we have one case where the different signedness of the two values of a ternary expression results in a warning. Given that: - `size` will always be bigger than `len` due to the loop condition. - `eol` will always be after `buf + len` because it is found via memchr(3p) starting from `buf + len`. We know that both values will always be natural integers. Squelch the warning by casting the left-hand side to `size_t`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7d200af commit 87318f2

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

gpg-interface.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#define USE_THE_REPOSITORY_VARIABLE
2-
#define DISABLE_SIGN_COMPARE_WARNINGS
32

43
#include "git-compat-util.h"
54
#include "commit.h"
@@ -128,19 +127,17 @@ static struct gpg_format *use_format = &gpg_format[0];
128127

129128
static struct gpg_format *get_format_by_name(const char *str)
130129
{
131-
int i;
132-
133-
for (i = 0; i < ARRAY_SIZE(gpg_format); i++)
130+
for (size_t i = 0; i < ARRAY_SIZE(gpg_format); i++)
134131
if (!strcmp(gpg_format[i].name, str))
135132
return gpg_format + i;
136133
return NULL;
137134
}
138135

139136
static struct gpg_format *get_format_by_sig(const char *sig)
140137
{
141-
int i, j;
138+
int j;
142139

143-
for (i = 0; i < ARRAY_SIZE(gpg_format); i++)
140+
for (size_t i = 0; i < ARRAY_SIZE(gpg_format); i++)
144141
for (j = 0; gpg_format[i].sigs[j]; j++)
145142
if (starts_with(sig, gpg_format[i].sigs[j]))
146143
return gpg_format + i;
@@ -228,7 +225,7 @@ static void parse_gpg_output(struct signature_check *sigc)
228225
{
229226
const char *buf = sigc->gpg_status;
230227
const char *line, *next;
231-
int i, j;
228+
int j;
232229
int seen_exclusive_status = 0;
233230

234231
/* Iterate over all lines */
@@ -243,7 +240,7 @@ static void parse_gpg_output(struct signature_check *sigc)
243240
continue;
244241

245242
/* Iterate over all search strings */
246-
for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
243+
for (size_t i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
247244
if (skip_prefix(line, sigcheck_gpg_status[i].check, &line)) {
248245
/*
249246
* GOODSIG, BADSIG etc. can occur only once for
@@ -700,7 +697,7 @@ size_t parse_signed_buffer(const char *buf, size_t size)
700697
match = len;
701698

702699
eol = memchr(buf + len, '\n', size - len);
703-
len += eol ? eol - (buf + len) + 1 : size - len;
700+
len += eol ? (size_t) (eol - (buf + len) + 1) : size - len;
704701
}
705702
return match;
706703
}

0 commit comments

Comments
 (0)