Skip to content

Commit 2bfd3b3

Browse files
arnavbhategitster
authored andcommitted
decorate: fix sign comparison warnings
There are multiple instances where ints have been initialized with values of unsigned ints, and where negative values don't mean anything. When such ints are compared with unsigned ints, it causes sign comparison warnings. Also, some of these are used just as stand-ins for their initial values, never being modified, thus obscuring the specific conditions under which certain operations happen. Replace int with unsigned int for 2 variables, and replace the intermediate variables with their initial values for 2 other variables. Signed-off-by: Arnav Bhate <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 87a0bdb commit 2bfd3b3

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

decorate.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* data.
44
*/
55

6-
#define DISABLE_SIGN_COMPARE_WARNINGS
7-
86
#include "git-compat-util.h"
97
#include "object.h"
108
#include "decorate.h"
@@ -16,17 +14,16 @@ static unsigned int hash_obj(const struct object *obj, unsigned int n)
1614

1715
static void *insert_decoration(struct decoration *n, const struct object *base, void *decoration)
1816
{
19-
int size = n->size;
2017
struct decoration_entry *entries = n->entries;
21-
unsigned int j = hash_obj(base, size);
18+
unsigned int j = hash_obj(base, n->size);
2219

2320
while (entries[j].base) {
2421
if (entries[j].base == base) {
2522
void *old = entries[j].decoration;
2623
entries[j].decoration = decoration;
2724
return old;
2825
}
29-
if (++j >= size)
26+
if (++j >= n->size)
3027
j = 0;
3128
}
3229
entries[j].base = base;
@@ -37,8 +34,8 @@ static void *insert_decoration(struct decoration *n, const struct object *base,
3734

3835
static void grow_decoration(struct decoration *n)
3936
{
40-
int i;
41-
int old_size = n->size;
37+
unsigned int i;
38+
unsigned int old_size = n->size;
4239
struct decoration_entry *old_entries = n->entries;
4340

4441
n->size = (old_size + 1000) * 3 / 2;
@@ -59,9 +56,7 @@ static void grow_decoration(struct decoration *n)
5956
void *add_decoration(struct decoration *n, const struct object *obj,
6057
void *decoration)
6158
{
62-
int nr = n->nr + 1;
63-
64-
if (nr > n->size * 2 / 3)
59+
if ((n->nr + 1) > n->size * 2 / 3)
6560
grow_decoration(n);
6661
return insert_decoration(n, obj, decoration);
6762
}

0 commit comments

Comments
 (0)