@@ -8,7 +8,7 @@ struct git_pool_page {
8
8
git_pool_page * next ;
9
9
uint32_t size ;
10
10
uint32_t avail ;
11
- char data [GIT_FLEX_ARRAY ];
11
+ GIT_ALIGN ( char data [GIT_FLEX_ARRAY ], 8 ) ;
12
12
};
13
13
14
14
static void * pool_alloc_page (git_pool * pool , uint32_t size );
@@ -30,11 +30,8 @@ uint32_t git_pool__system_page_size(void)
30
30
31
31
void git_pool_init (git_pool * pool , uint32_t item_size )
32
32
{
33
- const uint32_t align_size = sizeof (void * ) - 1 ;
34
33
assert (pool );
35
-
36
- if (item_size > 1 )
37
- item_size = (item_size + align_size ) & ~align_size ;
34
+ assert (item_size >= 1 );
38
35
39
36
memset (pool , 0 , sizeof (git_pool ));
40
37
pool -> item_size = item_size ;
@@ -98,15 +95,26 @@ static void *pool_alloc(git_pool *pool, uint32_t size)
98
95
return ptr ;
99
96
}
100
97
98
+ static uint32_t alloc_size (git_pool * pool , uint32_t count )
99
+ {
100
+ const uint32_t align = sizeof (void * ) - 1 ;
101
+
102
+ if (pool -> item_size > 1 ) {
103
+ const uint32_t item_size = (pool -> item_size + align ) & ~align ;
104
+ return item_size * count ;
105
+ }
106
+
107
+ return (count + align ) & ~align ;
108
+ }
109
+
101
110
void * git_pool_malloc (git_pool * pool , uint32_t items )
102
111
{
103
- const uint32_t size = items * pool -> item_size ;
104
- return pool_alloc (pool , size );
112
+ return pool_alloc (pool , alloc_size (pool , items ));
105
113
}
106
114
107
115
void * git_pool_mallocz (git_pool * pool , uint32_t items )
108
116
{
109
- const uint32_t size = items * pool -> item_size ;
117
+ const uint32_t size = alloc_size ( pool , items ) ;
110
118
void * ptr = pool_alloc (pool , size );
111
119
if (ptr )
112
120
memset (ptr , 0x0 , size );
0 commit comments