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
fa48d2ea
Commit
fa48d2ea
authored
Sep 26, 2018
by
Etienne Samson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vector: do not malloc 0-length vectors on dup
parent
c70713d6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
6 deletions
+27
-6
src/vector.c
+8
-6
tests/core/vector.c
+19
-0
No files found.
src/vector.c
View file @
fa48d2ea
...
...
@@ -50,22 +50,24 @@ int git_vector_size_hint(git_vector *v, size_t size_hint)
int
git_vector_dup
(
git_vector
*
v
,
const
git_vector
*
src
,
git_vector_cmp
cmp
)
{
size_t
bytes
;
assert
(
v
&&
src
);
GITERR_CHECK_ALLOC_MULTIPLY
(
&
bytes
,
src
->
length
,
sizeof
(
void
*
));
v
->
_alloc_size
=
src
->
length
;
v
->
_alloc_size
=
0
;
v
->
contents
=
NULL
;
v
->
_cmp
=
cmp
?
cmp
:
src
->
_cmp
;
v
->
length
=
src
->
length
;
v
->
flags
=
src
->
flags
;
if
(
cmp
!=
src
->
_cmp
)
git_vector_set_sorted
(
v
,
0
);
if
(
src
->
length
)
{
size_t
bytes
;
GITERR_CHECK_ALLOC_MULTIPLY
(
&
bytes
,
src
->
length
,
sizeof
(
void
*
));
v
->
contents
=
git__malloc
(
bytes
);
GITERR_CHECK_ALLOC
(
v
->
contents
);
v
->
_alloc_size
=
src
->
length
;
memcpy
(
v
->
contents
,
src
->
contents
,
bytes
);
}
return
0
;
}
...
...
tests/core/vector.c
View file @
fa48d2ea
...
...
@@ -407,3 +407,22 @@ void test_core_vector__reverse(void)
git_vector_free
(
&
v
);
}
void
test_core_vector__dup_empty_vector
(
void
)
{
git_vector
v
=
GIT_VECTOR_INIT
;
git_vector
dup
=
GIT_VECTOR_INIT
;
void
*
dummy
=
0xDEAFBEEB
;
cl_assert_equal_i
(
0
,
v
.
length
);
cl_git_pass
(
git_vector_dup
(
&
dup
,
&
v
,
v
.
_cmp
));
cl_assert_equal_i
(
0
,
dup
.
_alloc_size
);
cl_assert_equal_i
(
0
,
dup
.
length
);
cl_git_pass
(
git_vector_insert
(
&
dup
,
dummy
));
cl_assert_equal_i
(
8
,
dup
.
_alloc_size
);
cl_assert_equal_i
(
1
,
dup
.
length
);
git_vector_free
(
&
dup
);
}
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