Fix some "signed v unsigned comparison" warnings with -Wextra Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
diff --git a/src/errors.c b/src/errors.c
index f348997..f206b37 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -40,7 +40,7 @@ static struct {
const char *git_strerror(int num)
{
- int i;
+ size_t i;
if (num == GIT_EOSERR)
return strerror(errno);
diff --git a/src/odb.c b/src/odb.c
index eb9264e..92ff646 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -124,14 +124,14 @@ GIT_INLINE(uint64_t) decode64(void *b)
const char *git_obj_type_to_string(git_otype type)
{
- if (type < 0 || type >= ARRAY_SIZE(obj_type_table))
+ if (type < 0 || ((size_t) type) >= ARRAY_SIZE(obj_type_table))
return "";
return obj_type_table[type].str;
}
git_otype git_obj_string_to_type(const char *str)
{
- int i;
+ size_t i;
if (!str || !*str)
return GIT_OBJ_BAD;
@@ -145,7 +145,7 @@ git_otype git_obj_string_to_type(const char *str)
int git_obj__loose_object_type(git_otype type)
{
- if (type < 0 || type >= ARRAY_SIZE(obj_type_table))
+ if (type < 0 || ((size_t) type) >= ARRAY_SIZE(obj_type_table))
return 0;
return obj_type_table[type].loose;
}
@@ -155,10 +155,10 @@ static int format_object_header(char *hdr, size_t n, git_obj *obj)
const char *type_str = git_obj_type_to_string(obj->type);
int len = snprintf(hdr, n, "%s %"PRIuZ, type_str, obj->len);
- assert(len > 0); /* otherwise snprintf() is broken */
- assert(len < n); /* otherwise the caller is broken! */
+ assert(len > 0); /* otherwise snprintf() is broken */
+ assert(((size_t) len) < n); /* otherwise the caller is broken! */
- if (len < 0 || len >= n)
+ if (len < 0 || ((size_t) len) >= n)
return GIT_ERROR;
return len+1;
}
diff --git a/src/oid.c b/src/oid.c
index 97603e2..182859f 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -49,7 +49,7 @@ static char to_hex[] = "0123456789abcdef";
int git_oid_mkstr(git_oid *out, const char *str)
{
- int p;
+ size_t p;
for (p = 0; p < sizeof(out->id); p++, str += 2) {
int v = (from_hex[(unsigned char)str[0]] << 4)
| from_hex[(unsigned char)str[1]];
@@ -69,7 +69,7 @@ GIT_INLINE(char) *fmt_one(char *str, unsigned int val)
void git_oid_fmt(char *str, const git_oid *oid)
{
- int i;
+ size_t i;
for (i = 0; i < sizeof(oid->id); i++)
str = fmt_one(str, oid->id[i]);
@@ -77,7 +77,7 @@ void git_oid_fmt(char *str, const git_oid *oid)
void git_oid_pathfmt(char *str, const git_oid *oid)
{
- int i;
+ size_t i;
str = fmt_one(str, oid->id[0]);
*str++ = '/';
diff --git a/src/util.c b/src/util.c
index 09197a3..84a5237 100644
--- a/src/util.c
+++ b/src/util.c
@@ -35,7 +35,7 @@ int git__fmt(char *buf, size_t buf_sz, const char *fmt, ...)
va_start(va, fmt);
r = vsnprintf(buf, buf_sz, fmt, va);
va_end(va);
- if (r < 0 || r >= buf_sz)
+ if (r < 0 || ((size_t) r) >= buf_sz)
return GIT_ERROR;
return r;
}