[vlc-commits] vlc_arrays: split array_insert in checked and w/abort
Francois Cartegnie
git at videolan.org
Wed Oct 25 12:37:13 CEST 2017
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Oct 25 12:02:28 2017 +0200| [f49cd8802b46561d1420fff0733d2053f54da8e8] | committer: Francois Cartegnie
vlc_arrays: split array_insert in checked and w/abort
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f49cd8802b46561d1420fff0733d2053f54da8e8
---
include/vlc_arrays.h | 11 +++++++++--
lib/media_list.c | 2 +-
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/include/vlc_arrays.h b/include/vlc_arrays.h
index 1e38637516..54665346e0 100644
--- a/include/vlc_arrays.h
+++ b/include/vlc_arrays.h
@@ -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 )
diff --git a/lib/media_list.c b/lib/media_list.c
index 463d039966..7c93e41d5f 100644
--- a/lib/media_list.c
+++ b/lib/media_list.c
@@ -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 );
}
More information about the vlc-commits
mailing list