]> git.sesse.net Git - vlc/blobdiff - src/playlist/sort.c
quit fast when sorting a playlist with 1 or less entries. Fixes a crash when
[vlc] / src / playlist / sort.c
index ecf1346e4d2c7ccf97ce3bcfe14d8f26542686e2..2d0a0f9a8dad13833a228cc0662c34cdc2c10e11 100644 (file)
@@ -2,7 +2,7 @@
  * sort.c : Playlist sorting functions
  *****************************************************************************
  * Copyright (C) 1999-2004 VideoLAN
- * $Id: sort.c,v 1.9 2004/01/23 10:48:08 zorglub Exp $
+ * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
  *
@@ -25,6 +25,7 @@
 #include <string.h>                                            /* strerror() */
 
 #include <vlc/vlc.h>
+#include <vlc/input.h>
 #include <vlc/vout.h>
 #include <vlc/sout.h>
 
@@ -48,6 +49,17 @@ int playlist_Sort( playlist_t * p_playlist , int i_mode, int i_type )
 
     p_playlist->i_sort = i_mode;
     p_playlist->i_order = i_type;
+    /* playlist with one or less items are allways sorted in all
+       manners, quit fast. */
+    if( p_playlist->i_size <= 1 )
+    {
+        vlc_mutex_unlock( &p_playlist->object_lock );
+
+        /* Notify the interfaces, is this necessary? */
+        var_Set( p_playlist, "intf-change", val );
+
+        return VLC_SUCCESS;
+    }
 
     if( i_mode == SORT_RANDOM )
     {
@@ -87,18 +99,18 @@ int playlist_Sort( playlist_t * p_playlist , int i_mode, int i_type )
             }
             else if( i_mode == SORT_TITLE )
             {
-                i_test = strcasecmp( p_playlist->pp_items[i]->psz_name,
-                                 p_playlist->pp_items[i_small]->psz_name );
+                i_test = strcasecmp( p_playlist->pp_items[i]->input.psz_name,
+                             p_playlist->pp_items[i_small]->input.psz_name );
             }
             else if( i_mode == SORT_GROUP )
             {
                 i_test = p_playlist->pp_items[i]->i_group -
-                                 p_playlist->pp_items[i_small]->i_group;
+                             p_playlist->pp_items[i_small]->i_group;
             }
             else if( i_mode == SORT_DURATION )
             {
-                i_test = p_playlist->pp_items[i]->i_duration -
-                                 p_playlist->pp_items[i_small]->i_duration;
+                i_test = p_playlist->pp_items[i]->input.i_duration -
+                             p_playlist->pp_items[i_small]->input.i_duration;
             }
             else if( i_mode == SORT_AUTHOR )
             {