Skip to content

Commit 7186408

Browse files
committed
Merge branch 'rj/no-sign-compare' into maint
Many codepaths have been updated to squelch -Wsign-compare warnings. * rj/no-sign-compare: ALLOC_GROW: avoid -Wsign-compare warnings cache.h: hex2chr() - avoid -Wsign-compare warnings commit-slab.h: avoid -Wsign-compare warnings git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings
2 parents dd3bfe4 + 071bcaa commit 7186408

File tree

10 files changed

+25
-24
lines changed

10 files changed

+25
-24
lines changed

builtin/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,8 +2562,8 @@ struct in_pack_object {
25622562
};
25632563

25642564
struct in_pack {
2565-
int alloc;
2566-
int nr;
2565+
unsigned int alloc;
2566+
unsigned int nr;
25672567
struct in_pack_object *array;
25682568
};
25692569

cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,8 +1264,8 @@ static inline unsigned int hexval(unsigned char c)
12641264
*/
12651265
static inline int hex2chr(const char *s)
12661266
{
1267-
int val = hexval(s[0]);
1268-
return (val < 0) ? val : (val << 4) | hexval(s[1]);
1267+
unsigned int val = hexval(s[0]);
1268+
return (val & ~0xf) ? val : (val << 4) | hexval(s[1]);
12691269
}
12701270

12711271
/* Convert to/from hex/sha1 representation */

commit-slab.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static MAYBE_UNUSED void init_ ##slabname(struct slabname *s) \
7878
\
7979
static MAYBE_UNUSED void clear_ ##slabname(struct slabname *s) \
8080
{ \
81-
int i; \
81+
unsigned int i; \
8282
for (i = 0; i < s->slab_count; i++) \
8383
free(s->slab[i]); \
8484
s->slab_count = 0; \
@@ -89,13 +89,13 @@ static MAYBE_UNUSED elemtype *slabname## _at_peek(struct slabname *s, \
8989
const struct commit *c, \
9090
int add_if_missing) \
9191
{ \
92-
int nth_slab, nth_slot; \
92+
unsigned int nth_slab, nth_slot; \
9393
\
9494
nth_slab = c->index / s->slab_size; \
9595
nth_slot = c->index % s->slab_size; \
9696
\
9797
if (s->slab_count <= nth_slab) { \
98-
int i; \
98+
unsigned int i; \
9999
if (!add_if_missing) \
100100
return NULL; \
101101
REALLOC_ARRAY(s->slab, nth_slab + 1); \

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2155,7 +2155,7 @@ static struct {
21552155
size_t *offset;
21562156
unsigned int offset_alloc;
21572157
enum { START, SECTION_SEEN, SECTION_END_SEEN, KEY_SEEN } state;
2158-
int seen;
2158+
unsigned int seen;
21592159
} store;
21602160

21612161
static int matches(const char *key, const char *value)

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ static void emit_rewrite_diff(const char *name_a,
828828

829829
struct diff_words_buffer {
830830
mmfile_t text;
831-
long alloc;
831+
unsigned long alloc;
832832
struct diff_words_orig {
833833
const char *begin, *end;
834834
} *orig;

git-compat-util.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,11 @@ static inline char *xstrdup_or_null(const char *str)
900900

901901
static inline size_t xsize_t(off_t len)
902902
{
903-
if (len > (size_t) len)
903+
size_t size = (size_t) len;
904+
905+
if (len != (off_t) size)
904906
die("Cannot handle files this big");
905-
return (size_t)len;
907+
return size;
906908
}
907909

908910
__attribute__((format (printf, 3, 4)))

line-log.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static int range_cmp(const void *_r, const void *_s)
9090
*/
9191
static void range_set_check_invariants(struct range_set *rs)
9292
{
93-
int i;
93+
unsigned int i;
9494

9595
if (!rs)
9696
return;
@@ -110,8 +110,8 @@ static void range_set_check_invariants(struct range_set *rs)
110110
*/
111111
void sort_and_merge_range_set(struct range_set *rs)
112112
{
113-
int i;
114-
int o = 0; /* output cursor */
113+
unsigned int i;
114+
unsigned int o = 0; /* output cursor */
115115

116116
QSORT(rs->ranges, rs->nr, range_cmp);
117117

@@ -144,7 +144,7 @@ void sort_and_merge_range_set(struct range_set *rs)
144144
static void range_set_union(struct range_set *out,
145145
struct range_set *a, struct range_set *b)
146146
{
147-
int i = 0, j = 0;
147+
unsigned int i = 0, j = 0;
148148
struct range *ra = a->ranges;
149149
struct range *rb = b->ranges;
150150
/* cannot make an alias of out->ranges: it may change during grow */
@@ -186,7 +186,7 @@ static void range_set_union(struct range_set *out,
186186
static void range_set_difference(struct range_set *out,
187187
struct range_set *a, struct range_set *b)
188188
{
189-
int i, j = 0;
189+
unsigned int i, j = 0;
190190
for (i = 0; i < a->nr; i++) {
191191
long start = a->ranges[i].start;
192192
long end = a->ranges[i].end;
@@ -397,7 +397,7 @@ static void diff_ranges_filter_touched(struct diff_ranges *out,
397397
struct diff_ranges *diff,
398398
struct range_set *rs)
399399
{
400-
int i, j = 0;
400+
unsigned int i, j = 0;
401401

402402
assert(out->target.nr == 0);
403403

@@ -426,7 +426,7 @@ static void range_set_shift_diff(struct range_set *out,
426426
struct range_set *rs,
427427
struct diff_ranges *diff)
428428
{
429-
int i, j = 0;
429+
unsigned int i, j = 0;
430430
long offset = 0;
431431
struct range *src = rs->ranges;
432432
struct range *target = diff->target.ranges;
@@ -873,7 +873,7 @@ static char *output_prefix(struct diff_options *opt)
873873

874874
static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *range)
875875
{
876-
int i, j = 0;
876+
unsigned int i, j = 0;
877877
long p_lines, t_lines;
878878
unsigned long *p_ends = NULL, *t_ends = NULL;
879879
struct diff_filepair *pair = range->pair;
@@ -906,7 +906,7 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang
906906
long t_start = range->ranges.ranges[i].start;
907907
long t_end = range->ranges.ranges[i].end;
908908
long t_cur = t_start;
909-
int j_last;
909+
unsigned int j_last;
910910

911911
while (j < diff->target.nr && diff->target.ranges[j].end < t_start)
912912
j++;

line-log.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct range {
1414

1515
/* A set of ranges. The ranges must always be disjoint and sorted. */
1616
struct range_set {
17-
int alloc, nr;
17+
unsigned int alloc, nr;
1818
struct range *ranges;
1919
};
2020

revision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ static void add_rev_cmdline(struct rev_info *revs,
11031103
unsigned flags)
11041104
{
11051105
struct rev_cmdline_info *info = &revs->cmdline;
1106-
int nr = info->nr;
1106+
unsigned int nr = info->nr;
11071107

11081108
ALLOC_GROW(info->rev, nr + 1, info->alloc);
11091109
info->rev[nr].item = item;

tree-walk.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,11 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
581581
int retval = MISSING_OBJECT;
582582
struct dir_state *parents = NULL;
583583
size_t parents_alloc = 0;
584-
ssize_t parents_nr = 0;
584+
size_t i, parents_nr = 0;
585585
unsigned char current_tree_sha1[20];
586586
struct strbuf namebuf = STRBUF_INIT;
587587
struct tree_desc t;
588588
int follows_remaining = GET_TREE_ENTRY_FOLLOW_SYMLINKS_MAX_LINKS;
589-
int i;
590589

591590
init_tree_desc(&t, NULL, 0UL);
592591
strbuf_addstr(&namebuf, name);

0 commit comments

Comments
 (0)