File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed
Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 4141
4242typedef git_array_t (char ) git_array_generic_t ;
4343
44- /* use a generic array for growth so this can return the new item */
45- GIT_INLINE (void * ) git_array_grow (void * _a , size_t item_size )
44+ /* use a generic array for growth, return 0 on success */
45+ GIT_INLINE (int ) git_array_grow (void * _a , size_t item_size )
4646{
4747 volatile git_array_generic_t * a = _a ;
4848 size_t new_size ;
@@ -59,18 +59,18 @@ GIT_INLINE(void *) git_array_grow(void *_a, size_t item_size)
5959 if ((new_array = git__reallocarray (a -> ptr , new_size , item_size )) == NULL )
6060 goto on_oom ;
6161
62- a -> ptr = new_array ; a -> asize = new_size ; a -> size ++ ;
63- return a -> ptr + (a -> size - 1 ) * item_size ;
62+ a -> ptr = new_array ;
63+ a -> asize = new_size ;
64+ return 0 ;
6465
6566on_oom :
6667 git_array_clear (* a );
67- return NULL ;
68+ return -1 ;
6869}
6970
7071#define git_array_alloc (a ) \
71- (((a).size >= (a).asize) ? \
72- git_array_grow(&(a), sizeof(*(a).ptr)) : \
73- ((a).ptr ? &(a).ptr[(a).size++] : (void *)NULL))
72+ (((a).size < (a).asize || git_array_grow(&(a), sizeof(*(a).ptr)) == 0) ? \
73+ &(a).ptr[(a).size++] : (void *)NULL)
7474
7575#define git_array_last (a ) ((a).size ? &(a).ptr[(a).size - 1] : (void *)NULL)
7676
You can’t perform that action at this time.
0 commit comments