[vlc-devel] commit: playlist: Don't assume that psz_name != NULL as GetName can return NULL and (Ilkka Ollakka )

git version control git at videolan.org
Fri Jan 2 09:56:37 CET 2009


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Fri Jan  2 10:55:17 2009 +0200| [08ada19951ded248011b1032cdabc2bc7ac971ae] | committer: Ilkka Ollakka 

playlist: Don't assume that psz_name != NULL as GetName can return NULL and
 strcasecmp doesn't like comparing NULLs

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=08ada19951ded248011b1032cdabc2bc7ac971ae
---

 src/playlist/sort.c |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/playlist/sort.c b/src/playlist/sort.c
index e8b6f3c..4301614 100644
--- a/src/playlist/sort.c
+++ b/src/playlist/sort.c
@@ -123,7 +123,10 @@ static int playlist_cmp(const void *first, const void *second)
 #define META_STRCASECMP_NAME( ) { \
     char *psz_i = input_item_GetName( (*(playlist_item_t **)first)->p_input ); \
     char *psz_ismall = input_item_GetName( (*(playlist_item_t **)second)->p_input ); \
-    i_test = strcasecmp( psz_i, psz_ismall ); \
+    if( psz_i != NULL && psz_ismall != NULL ) i_test = strcasecmp( psz_i, psz_ismall ); \
+    else if ( psz_i == NULL && psz_ismall != NULL ) i_test = 1; \
+    else if ( psz_ismall == NULL && psz_i != NULL ) i_test = -1; \
+    else i_test = 0; \
     free( psz_i ); \
     free( psz_ismall ); \
 }
@@ -232,8 +235,23 @@ static int playlist_cmp(const void *first, const void *second)
         }
         else
         {
-            i_test = strcasecmp( (*(playlist_item_t **)first)->p_input->psz_name,
+            if ( (*(playlist_item_t **)first)->p_input->psz_name != NULL &&
+                 (*(playlist_item_t **)second)->p_input->psz_name != NULL )
+            {
+                i_test = strcasecmp( (*(playlist_item_t **)first)->p_input->psz_name,
                                  (*(playlist_item_t **)second)->p_input->psz_name );
+            }
+            else if ( (*(playlist_item_t **)first)->p_input->psz_name != NULL &&
+                 (*(playlist_item_t **)second)->p_input->psz_name == NULL )
+            {
+                i_test = 1;
+            }
+            else if ( (*(playlist_item_t **)first)->p_input->psz_name == NULL &&
+                 (*(playlist_item_t **)second)->p_input->psz_name != NULL )
+            {
+                i_test = -1;
+            }
+            else i_test = 0;
         }
     }
     else if( sort_mode == SORT_URI )




More information about the vlc-devel mailing list