fix for #1533: check on array boundaries before removing media
authorFilippo Carone <littlejohn@videolan.org>
Fri, 21 Mar 2008 14:03:29 +0000 (15:03 +0100)
committerFilippo Carone <littlejohn@videolan.org>
Fri, 21 Mar 2008 14:03:29 +0000 (15:03 +0100)
bindings/java/core/src/test/java/org/videolan/jvlc/MediaListTest.java
src/control/media_list.c

index b5cb236..35cd1a9 100644 (file)
@@ -99,7 +99,14 @@ public class MediaListTest
         mlist.addMediaDescriptor(new MediaDescriptor(jvlc, mrl));
         mlist.removeMedia(new MediaDescriptor(jvlc, mrl));
         Assert.assertEquals(0, mlist.itemsCount());
-        
+    }
+    
+    @Test
+    public void mediaListRemoveNonExistingMedia()
+    {
+        MediaList mlist = new MediaList(jvlc);
+        boolean result = mlist.removeMedia(3);
+        Assert.assertFalse(result);
     }
     
     
index a88ed8c..4286fb9 100644 (file)
@@ -397,10 +397,15 @@ void _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
                                      int index,
                                      libvlc_exception_t * p_e )
 {
-    VLC_UNUSED(p_e);
 
     libvlc_media_descriptor_t * p_md;
 
+    if( index < 0 || index > vlc_array_count( &p_mlist->items ))
+    {
+        libvlc_exception_raise( p_e, "Index out of bounds exception");
+        return;
+    }
+            
     p_md = vlc_array_item_at_index( &p_mlist->items, index );
 
     notify_item_deletion( p_mlist, p_md, index, EventWillHappen );