Commit f49cd880 authored by François Cartegnie's avatar François Cartegnie 🤞

vlc_arrays: split array_insert in checked and w/abort

parent 9314bb48
......@@ -291,12 +291,12 @@ static inline ssize_t vlc_array_index_of_item( const vlc_array_t *ar,
}
/* Write */
static inline void vlc_array_insert( vlc_array_t *ar, void *elem, int idx )
static inline int vlc_array_insert( vlc_array_t *ar, void *elem, int idx )
{
void **pp = (void **)realloc( ar->pp_elems,
sizeof( void * ) * (ar->i_count + 1) );
if( unlikely(pp == NULL) )
abort();
return -1;
size_t tail = ar->i_count - idx;
if( tail > 0 )
......@@ -305,6 +305,13 @@ static inline void vlc_array_insert( vlc_array_t *ar, void *elem, int idx )
pp[idx] = elem;
ar->i_count++;
ar->pp_elems = pp;
return 0;
}
static inline void vlc_array_insert_or_abort( vlc_array_t *ar, void *elem, int idx )
{
if( vlc_array_insert( ar, elem, idx ) )
abort();
}
static inline int vlc_array_append( vlc_array_t *ar, void *elem )
......
......@@ -363,7 +363,7 @@ void libvlc_media_list_internal_insert_media( libvlc_media_list_t * p_mlist,
libvlc_media_retain( p_md );
notify_item_addition( p_mlist, p_md, index, EventWillHappen );
vlc_array_insert( &p_mlist->items, p_md, index );
vlc_array_insert_or_abort( &p_mlist->items, p_md, index );
notify_item_addition( p_mlist, p_md, index, EventDidHappen );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment