builtin/log: fix remaining -Wsign-compare warnings
Fix remaining -Wsign-compare warnings in "builtin/log.c" and mark the file as -Wsign-compare-clean. While most of the fixes are obvious, one fix requires us to use `cast_size_t_to_int()`, which will cause us to die in case the `size_t` cannot be represented as `int`. This should be fine though, as the data would typically be set either via a config key or via the command line, neither of which should ever exceed a couple of kilobytes of data. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 27, 2024 at 11:46 UTC
1ab5948141e62b52bcb812b04a901b3efaf1b578
1 file changed
+13
-14
builtin/log.c
+13
-14
@@ -6,7 +6,6 @@
6
*/
7
8
#define USE_THE_REPOSITORY_VARIABLE
9
-#define DISABLE_SIGN_COMPARE_WARNINGS
9
10
#include "builtin.h"
11
#include "abspath.h"
@@ -209,7 +208,6 @@ static void cmd_log_init_defaults(struct rev_info *rev,
208
209
static void set_default_decoration_filter(struct decoration_filter *decoration_filter)
210
{
212
- int i;
211
char *value = NULL;
212
struct string_list *include = decoration_filter->include_ref_pattern;
213
const struct string_list *config_exclude;
@@ -243,7 +241,7 @@ static void set_default_decoration_filter(struct decoration_filter *decoration_f
241
* No command-line or config options were given, so
242
* populate with sensible defaults.
243
*/
246
- for (i = 0; i < ARRAY_SIZE(ref_namespace); i++) {
244
+ for (size_t i = 0; i < ARRAY_SIZE(ref_namespace); i++) {
245
if (!ref_namespace[i].decoration)
246
continue;
247
@@ -717,14 +715,14 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
715
unsigned long size;
716
enum object_type type;
717
char *buf = repo_read_object_file(the_repository, oid, &type, &size);
720
- int offset = 0;
718
+ unsigned long offset = 0;
719
720
if (!buf)
721
return error(_("could not read object %s"), oid_to_hex(oid));
722
723
assert(type == OBJ_TAG);
724
while (offset < size && buf[offset] != '\n') {
727
- int new_offset = offset + 1;
725
+ unsigned long new_offset = offset + 1;
726
const char *ident;
727
while (new_offset < size && buf[new_offset++] != '\n')
728
; /* do nothing */
@@ -1316,24 +1314,25 @@ static void print_signature(const char *signature, FILE *file)
1314
1315
static char *find_branch_name(struct rev_info *rev)
1316
{
1319
- int i, positive = -1;
1317
struct object_id branch_oid;
1318
const struct object_id *tip_oid;
1319
const char *ref, *v;
1320
char *full_ref, *branch = NULL;
1321
+ int interesting_found = 0;
1322
+ size_t idx;
1323
1325
- for (i = 0; i < rev->cmdline.nr; i++) {
1324
+ for (size_t i = 0; i < rev->cmdline.nr; i++) {
1325
if (rev->cmdline.rev[i].flags & UNINTERESTING)
1326
continue;
1328
- if (positive < 0)
1329
- positive = i;
1330
- else
1327
+ if (interesting_found)
1328
return NULL;
1329
+ interesting_found = 1;
1330
+ idx = i;
1331
}
1333
- if (positive < 0)
1332
+ if (!interesting_found)
1333
return NULL;
1335
- ref = rev->cmdline.rev[positive].name;
1336
- tip_oid = &rev->cmdline.rev[positive].item->oid;
1334
+ ref = rev->cmdline.rev[idx].name;
1335
+ tip_oid = &rev->cmdline.rev[idx].item->oid;
1336
if (repo_dwim_ref(the_repository, ref, strlen(ref), &branch_oid,
1337
&full_ref, 0) &&
1338
skip_prefix(full_ref, "refs/heads/", &v) &&
@@ -2183,7 +2182,7 @@ int cmd_format_patch(int argc,
2182
fmt_patch_suffix = cfg.fmt_patch_suffix;
2183
2184
/* Make sure "0000-$sub.patch" gives non-negative length for $sub */
2186
- if (cfg.log.fmt_patch_name_max <= strlen("0000-") + strlen(fmt_patch_suffix))
2185
+ if (cfg.log.fmt_patch_name_max <= cast_size_t_to_int(strlen("0000-") + strlen(fmt_patch_suffix)))
2186
cfg.log.fmt_patch_name_max = strlen("0000-") + strlen(fmt_patch_suffix);
2187
2188
if (cover_from_description_arg)