diff --git a/src/dirlist.c b/src/dirlist.c
index 3b4c655755e5f7eab035a8bf9ea6c698fb388665..da51a98e4cfbc9fc25f2d7ced1a3c0ebec9b5acb 100644
--- a/src/dirlist.c
+++ b/src/dirlist.c
@@ -371,7 +371,8 @@ void dirlist_set_sort(int col, int desc, int df) {
     dirlist_sort_df = df;
 
   /* sort the list (excluding the parent, which is always on top) */
-  head_real = dirlist_sort(head_real);
+  if(head_real)
+    head_real = dirlist_sort(head_real);
   if(dirlist_parent)
     dirlist_parent->next = head_real;
   else