Commit 26e74c6acedaec5c76944ac1f1a0f9215f23737f

Sebastian Schuberth 2011-09-08T14:21:17

Fix some random size_t vs. int conversion warnings

diff --git a/include/git2/blob.h b/include/git2/blob.h
index e366ce8..97739d0 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -106,7 +106,7 @@ GIT_EXTERN(const void *) git_blob_rawcontent(git_blob *blob);
  * @param blob pointer to the blob
  * @return size on bytes
  */
-GIT_EXTERN(int) git_blob_rawsize(git_blob *blob);
+GIT_EXTERN(size_t) git_blob_rawsize(git_blob *blob);
 
 /**
  * Read a file from the working folder of a repository
diff --git a/src/blob.c b/src/blob.c
index b8282e5..0f4fa18 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -36,7 +36,7 @@ const void *git_blob_rawcontent(git_blob *blob)
 	return blob->odb_object->raw.data;
 }
 
-int git_blob_rawsize(git_blob *blob)
+size_t git_blob_rawsize(git_blob *blob)
 {
 	assert(blob);
 	return blob->odb_object->raw.len;
diff --git a/src/config_file.c b/src/config_file.c
index 520a806..4e5dd0b 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -135,7 +135,7 @@ static int cvar_match_section(const char *local, const char *input)
 {
 	char *first_dot;
 	char *local_sp = strchr(local, ' ');
-	int comparison_len;
+	size_t comparison_len;
 
 	/*
 	 * If the local section name doesn't contain a space, then we can
@@ -198,7 +198,8 @@ static int cvar_normalize_name(cvar_t *var, char **output)
 {
 	char *section_sp = strchr(var->section, ' ');
 	char *quote, *name;
-	int len, ret;
+	size_t len;
+	int ret;
 
 	/*
 	 * The final string is going to be at most one char longer than
@@ -245,7 +246,7 @@ static int cvar_normalize_name(cvar_t *var, char **output)
 static char *interiorize_section(const char *orig)
 {
 	char *dot, *last_dot, *section, *ret;
-	int len;
+	size_t len;
 
 	dot = strchr(orig, '.');
 	last_dot = strrchr(orig, '.');
@@ -530,7 +531,7 @@ static char *cfg_readline(diskfile_backend *cfg)
 {
 	char *line = NULL;
 	char *line_src, *line_end;
-	int line_len;
+	size_t line_len;
 
 	line_src = cfg->reader.read_ptr;
 
@@ -600,7 +601,8 @@ GIT_INLINE(int) config_keychar(int c)
 
 static int parse_section_header_ext(const char *line, const char *base_name, char **section_name)
 {
-	int buf_len, total_len, pos, rpos;
+	size_t buf_len, total_len;
+	int pos, rpos;
 	int c, ret;
 	char *subsection, *first_quote, *last_quote;
 	int error = GIT_SUCCESS;
@@ -1100,7 +1102,8 @@ static int is_multiline_var(const char *str)
 static int parse_multiline_variable(diskfile_backend *cfg, const char *first, char **out)
 {
 	char *line = NULL, *end;
-	int error = GIT_SUCCESS, len, ret;
+	int error = GIT_SUCCESS, ret;
+	size_t len;
 	char *buf;
 
 	/* Check that the next line exists */
diff --git a/src/indexer.c b/src/indexer.c
index 3934250..eb7d9d4 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -99,7 +99,7 @@ static int cache_cmp(const void *a, const void *b)
 int git_indexer_new(git_indexer **out, const char *packname)
 {
 	git_indexer *idx;
-	unsigned int namelen;
+	size_t namelen;
 	int ret, error;
 
 	assert(out && packname);
@@ -186,7 +186,8 @@ static void index_path(char *path, git_indexer *idx)
 int git_indexer_write(git_indexer *idx)
 {
 	git_mwindow *w = NULL;
-	int error, namelen;
+	int error;
+	size_t namelen;
 	unsigned int i, long_offsets = 0, left;
 	struct git_pack_idx_header hdr;
 	char filename[GIT_PATH_MAX];
diff --git a/src/util.c b/src/util.c
index 29bf755..a171f65 100644
--- a/src/util.c
+++ b/src/util.c
@@ -118,9 +118,9 @@ Return:
 	return GIT_SUCCESS;
 }
 
-void git__strntolower(char *str, int len)
+void git__strntolower(char *str, size_t len)
 {
-	int i;
+	size_t i;
 
 	for (i = 0; i < len; ++i) {
 		str[i] = (char) tolower(str[i]);
diff --git a/src/util.h b/src/util.h
index 78f9f82..2b00979 100644
--- a/src/util.h
+++ b/src/util.h
@@ -90,7 +90,7 @@ GIT_INLINE(int) git__is_sizet(git_off_t p)
 
 extern char *git__strtok(char **end, const char *sep);
 
-extern void git__strntolower(char *str, int len);
+extern void git__strntolower(char *str, size_t len);
 extern void git__strtolower(char *str);
 
 extern int git__fnmatch(const char *pattern, const char *name, int flags);