Git fork

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 <bhatearnav@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Arnav Bhate and committed by
Junio C Hamano
2bfd3b36 87a0bdbf

+5 -10
+5 -10
decorate.c
··· 3 3 * data. 4 4 */ 5 5 6 - #define DISABLE_SIGN_COMPARE_WARNINGS 7 - 8 6 #include "git-compat-util.h" 9 7 #include "object.h" 10 8 #include "decorate.h" ··· 16 14 17 15 static void *insert_decoration(struct decoration *n, const struct object *base, void *decoration) 18 16 { 19 - int size = n->size; 20 17 struct decoration_entry *entries = n->entries; 21 - unsigned int j = hash_obj(base, size); 18 + unsigned int j = hash_obj(base, n->size); 22 19 23 20 while (entries[j].base) { 24 21 if (entries[j].base == base) { ··· 26 23 entries[j].decoration = decoration; 27 24 return old; 28 25 } 29 - if (++j >= size) 26 + if (++j >= n->size) 30 27 j = 0; 31 28 } 32 29 entries[j].base = base; ··· 37 34 38 35 static void grow_decoration(struct decoration *n) 39 36 { 40 - int i; 41 - int old_size = n->size; 37 + unsigned int i; 38 + unsigned int old_size = n->size; 42 39 struct decoration_entry *old_entries = n->entries; 43 40 44 41 n->size = (old_size + 1000) * 3 / 2; ··· 59 56 void *add_decoration(struct decoration *n, const struct object *obj, 60 57 void *decoration) 61 58 { 62 - int nr = n->nr + 1; 63 - 64 - if (nr > n->size * 2 / 3) 59 + if ((n->nr + 1) > n->size * 2 / 3) 65 60 grow_decoration(n); 66 61 return insert_decoration(n, obj, decoration); 67 62 }