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
7ff7ca62
Commit
7ff7ca62
authored
Nov 12, 2015
by
Vicent Marti
Committed by
Carlos Martín Nieto
Nov 13, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pool: Never return unaligned buffers
parent
75a0ccf5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
10 deletions
+18
-10
src/pool.c
+16
-8
tests/core/pool.c
+2
-2
No files found.
src/pool.c
View file @
7ff7ca62
...
@@ -8,7 +8,7 @@ struct git_pool_page {
...
@@ -8,7 +8,7 @@ struct git_pool_page {
git_pool_page
*
next
;
git_pool_page
*
next
;
uint32_t
size
;
uint32_t
size
;
uint32_t
avail
;
uint32_t
avail
;
char
data
[
GIT_FLEX_ARRAY
]
;
GIT_ALIGN
(
char
data
[
GIT_FLEX_ARRAY
],
8
)
;
};
};
static
void
*
pool_alloc_page
(
git_pool
*
pool
,
uint32_t
size
);
static
void
*
pool_alloc_page
(
git_pool
*
pool
,
uint32_t
size
);
...
@@ -30,11 +30,8 @@ uint32_t git_pool__system_page_size(void)
...
@@ -30,11 +30,8 @@ uint32_t git_pool__system_page_size(void)
void
git_pool_init
(
git_pool
*
pool
,
uint32_t
item_size
)
void
git_pool_init
(
git_pool
*
pool
,
uint32_t
item_size
)
{
{
const
uint32_t
align_size
=
sizeof
(
void
*
)
-
1
;
assert
(
pool
);
assert
(
pool
);
assert
(
item_size
>=
1
);
if
(
item_size
>
1
)
item_size
=
(
item_size
+
align_size
)
&
~
align_size
;
memset
(
pool
,
0
,
sizeof
(
git_pool
));
memset
(
pool
,
0
,
sizeof
(
git_pool
));
pool
->
item_size
=
item_size
;
pool
->
item_size
=
item_size
;
...
@@ -98,15 +95,26 @@ static void *pool_alloc(git_pool *pool, uint32_t size)
...
@@ -98,15 +95,26 @@ static void *pool_alloc(git_pool *pool, uint32_t size)
return
ptr
;
return
ptr
;
}
}
static
uint32_t
alloc_size
(
git_pool
*
pool
,
uint32_t
count
)
{
const
uint32_t
align
=
sizeof
(
void
*
)
-
1
;
if
(
pool
->
item_size
>
1
)
{
const
uint32_t
item_size
=
(
pool
->
item_size
+
align
)
&
~
align
;
return
item_size
*
count
;
}
return
(
count
+
align
)
&
~
align
;
}
void
*
git_pool_malloc
(
git_pool
*
pool
,
uint32_t
items
)
void
*
git_pool_malloc
(
git_pool
*
pool
,
uint32_t
items
)
{
{
const
uint32_t
size
=
items
*
pool
->
item_size
;
return
pool_alloc
(
pool
,
alloc_size
(
pool
,
items
));
return
pool_alloc
(
pool
,
size
);
}
}
void
*
git_pool_mallocz
(
git_pool
*
pool
,
uint32_t
items
)
void
*
git_pool_mallocz
(
git_pool
*
pool
,
uint32_t
items
)
{
{
const
uint32_t
size
=
items
*
pool
->
item_size
;
const
uint32_t
size
=
alloc_size
(
pool
,
items
)
;
void
*
ptr
=
pool_alloc
(
pool
,
size
);
void
*
ptr
=
pool_alloc
(
pool
,
size
);
if
(
ptr
)
if
(
ptr
)
memset
(
ptr
,
0x0
,
size
);
memset
(
ptr
,
0x0
,
size
);
...
...
tests/core/pool.c
View file @
7ff7ca62
...
@@ -32,7 +32,7 @@ void test_core_pool__1(void)
...
@@ -32,7 +32,7 @@ void test_core_pool__1(void)
cl_assert
(
git_pool_malloc
(
&
p
,
i
)
!=
NULL
);
cl_assert
(
git_pool_malloc
(
&
p
,
i
)
!=
NULL
);
/* with fixed page size, allocation must end up with these values */
/* with fixed page size, allocation must end up with these values */
cl_assert_equal_i
(
59
0
,
git_pool__open_pages
(
&
p
));
cl_assert_equal_i
(
59
1
,
git_pool__open_pages
(
&
p
));
git_pool_clear
(
&
p
);
git_pool_clear
(
&
p
);
git_pool_init
(
&
p
,
1
);
git_pool_init
(
&
p
,
1
);
...
@@ -42,7 +42,7 @@ void test_core_pool__1(void)
...
@@ -42,7 +42,7 @@ void test_core_pool__1(void)
cl_assert
(
git_pool_malloc
(
&
p
,
i
)
!=
NULL
);
cl_assert
(
git_pool_malloc
(
&
p
,
i
)
!=
NULL
);
/* with fixed page size, allocation must end up with these values */
/* with fixed page size, allocation must end up with these values */
cl_assert_equal_i
(
573
,
git_pool__open_pages
(
&
p
));
cl_assert_equal_i
(
sizeof
(
void
*
)
==
8
?
575
:
573
,
git_pool__open_pages
(
&
p
));
git_pool_clear
(
&
p
);
git_pool_clear
(
&
p
);
}
}
...
...
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