Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
aadad405
Commit
aadad405
authored
9 years ago
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tree: zap warnings around `size_t` vs `uint16_t`
parent
35439f59
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
src/tree.c
+16
-10
No files found.
src/tree.c
View file @
aadad405
...
...
@@ -17,6 +17,9 @@
#define DEFAULT_TREE_SIZE 16
#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
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
git_tree_entry
*
entry
=
NULL
;
size_t
tree_len
;
if
(
filename_len
>
UINT16_MAX
)
{
giterr_set
(
GITERR_INVALID
,
"tree entry is over UINT16_MAX in length"
);
return
NULL
;
}
TREE_ENTRY_CHECK_NAMELEN
(
filename_len
);
if
(
GIT_ADD_SIZET_OVERFLOW
(
&
tree_len
,
sizeof
(
git_tree_entry
),
filename_len
)
||
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
memset
(
entry
,
0x0
,
sizeof
(
git_tree_entry
));
memcpy
(
entry
->
filename
,
filename
,
filename_len
);
entry
->
filename
[
filename_len
]
=
0
;
entry
->
filename_len
=
filename_len
;
entry
->
filename_len
=
(
uint16_t
)
filename_len
;
return
entry
;
}
...
...
@@ -143,8 +143,8 @@ static int homing_search_cmp(const void *key, const void *array_member)
const
struct
tree_key_search
*
ksearch
=
key
;
const
git_tree_entry
*
entry
=
array_member
;
const
size
_t
len1
=
ksearch
->
filename_len
;
const
size
_t
len2
=
entry
->
filename_len
;
const
uint16
_t
len1
=
ksearch
->
filename_len
;
const
uint16
_t
len2
=
entry
->
filename_len
;
return
memcmp
(
ksearch
->
filename
,
...
...
@@ -180,8 +180,10 @@ static int tree_key_search(
const
git_tree_entry
*
entry
;
size_t
homing
,
i
;
TREE_ENTRY_CHECK_NAMELEN
(
filename_len
);
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
* the same prefix as the filename we're looking for */
...
...
@@ -334,6 +336,7 @@ const git_tree_entry *git_tree_entry_byname(
const
git_tree
*
tree
,
const
char
*
filename
)
{
assert
(
tree
&&
filename
);
return
entry_fromname
(
tree
,
filename
,
strlen
(
filename
));
}
...
...
@@ -364,13 +367,16 @@ int git_tree__prefix_position(const git_tree *tree, const char *path)
{
const
git_vector
*
entries
=
&
tree
->
entries
;
struct
tree_key_search
ksearch
;
size_t
at_pos
;
size_t
at_pos
,
path_len
;
if
(
!
path
)
return
0
;
path_len
=
strlen
(
path
);
TREE_ENTRY_CHECK_NAMELEN
(
path_len
);
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 */
assert
(
git_vector_is_sorted
(
&
tree
->
entries
));
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment