Commit aadad405 by Edward Thomson

tree: zap warnings around `size_t` vs `uint16_t`

parent 35439f59
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
#define DEFAULT_TREE_SIZE 16 #define DEFAULT_TREE_SIZE 16
#define MAX_FILEMODE_BYTES 6 #define MAX_FILEMODE_BYTES 6
#define TREE_ENTRY_CHECK_NAMELEN(n) \
if (n > UINT16_MAX) { giterr_set(GITERR_INVALID, "tree entry path too long"); }
GIT__USE_STRMAP GIT__USE_STRMAP
static bool valid_filemode(const int filemode) static bool valid_filemode(const int filemode)
...@@ -89,10 +92,7 @@ static git_tree_entry *alloc_entry_base(git_pool *pool, const char *filename, si ...@@ -89,10 +92,7 @@ static git_tree_entry *alloc_entry_base(git_pool *pool, const char *filename, si
git_tree_entry *entry = NULL; git_tree_entry *entry = NULL;
size_t tree_len; size_t tree_len;
if (filename_len > UINT16_MAX) { TREE_ENTRY_CHECK_NAMELEN(filename_len);
giterr_set(GITERR_INVALID, "tree entry is over UINT16_MAX in length");
return NULL;
}
if (GIT_ADD_SIZET_OVERFLOW(&tree_len, sizeof(git_tree_entry), filename_len) || if (GIT_ADD_SIZET_OVERFLOW(&tree_len, sizeof(git_tree_entry), filename_len) ||
GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, 1)) GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, 1))
...@@ -106,7 +106,7 @@ static git_tree_entry *alloc_entry_base(git_pool *pool, const char *filename, si ...@@ -106,7 +106,7 @@ static git_tree_entry *alloc_entry_base(git_pool *pool, const char *filename, si
memset(entry, 0x0, sizeof(git_tree_entry)); memset(entry, 0x0, sizeof(git_tree_entry));
memcpy(entry->filename, filename, filename_len); memcpy(entry->filename, filename, filename_len);
entry->filename[filename_len] = 0; entry->filename[filename_len] = 0;
entry->filename_len = filename_len; entry->filename_len = (uint16_t)filename_len;
return entry; return entry;
} }
...@@ -143,8 +143,8 @@ static int homing_search_cmp(const void *key, const void *array_member) ...@@ -143,8 +143,8 @@ static int homing_search_cmp(const void *key, const void *array_member)
const struct tree_key_search *ksearch = key; const struct tree_key_search *ksearch = key;
const git_tree_entry *entry = array_member; const git_tree_entry *entry = array_member;
const size_t len1 = ksearch->filename_len; const uint16_t len1 = ksearch->filename_len;
const size_t len2 = entry->filename_len; const uint16_t len2 = entry->filename_len;
return memcmp( return memcmp(
ksearch->filename, ksearch->filename,
...@@ -180,8 +180,10 @@ static int tree_key_search( ...@@ -180,8 +180,10 @@ static int tree_key_search(
const git_tree_entry *entry; const git_tree_entry *entry;
size_t homing, i; size_t homing, i;
TREE_ENTRY_CHECK_NAMELEN(filename_len);
ksearch.filename = filename; ksearch.filename = filename;
ksearch.filename_len = filename_len; ksearch.filename_len = (uint16_t)filename_len;
/* Initial homing search; find an entry on the tree with /* Initial homing search; find an entry on the tree with
* the same prefix as the filename we're looking for */ * the same prefix as the filename we're looking for */
...@@ -334,6 +336,7 @@ const git_tree_entry *git_tree_entry_byname( ...@@ -334,6 +336,7 @@ const git_tree_entry *git_tree_entry_byname(
const git_tree *tree, const char *filename) const git_tree *tree, const char *filename)
{ {
assert(tree && filename); assert(tree && filename);
return entry_fromname(tree, filename, strlen(filename)); return entry_fromname(tree, filename, strlen(filename));
} }
...@@ -364,13 +367,16 @@ int git_tree__prefix_position(const git_tree *tree, const char *path) ...@@ -364,13 +367,16 @@ int git_tree__prefix_position(const git_tree *tree, const char *path)
{ {
const git_vector *entries = &tree->entries; const git_vector *entries = &tree->entries;
struct tree_key_search ksearch; struct tree_key_search ksearch;
size_t at_pos; size_t at_pos, path_len;
if (!path) if (!path)
return 0; return 0;
path_len = strlen(path);
TREE_ENTRY_CHECK_NAMELEN(path_len);
ksearch.filename = path; ksearch.filename = path;
ksearch.filename_len = strlen(path); ksearch.filename_len = (uint16_t)path_len;
/* be safe when we cast away constness - i.e. don't trigger a sort */ /* be safe when we cast away constness - i.e. don't trigger a sort */
assert(git_vector_is_sorted(&tree->entries)); assert(git_vector_is_sorted(&tree->entries));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment