Attempt to fix a crash in FolderStatusModel::slotUpdateDirectories
authorOlivier Goffart <ogoffart@woboq.com>
Wed, 15 Mar 2017 16:17:33 +0000 (17:17 +0100)
committerOlivier Goffart <ogoffart@woboq.com>
Wed, 15 Mar 2017 16:23:39 +0000 (17:23 +0100)
The backtrace looks like:

  File "atomic_base.h", line 396, in QString::~QString
  File "qlist.h", line 442, in OCC::FolderStatusModel::slotUpdateDirectories

This is the only QList operation, and it may crash if the list is empty.
It can be empty if the propfind returned empty results.
I'm not sure how this can be possible to have an empty list there since
the server is always supposed to return at least one entry, for the directory
itself. But it can happen if a directory was transformed in a file, or
if there is a bug on the server.

src/gui/folderstatusmodel.cpp

index 65ff918d5bb88210dc7eedec0a4f12f8eb023bf0..a4079ff07ce6648943bd3521cd4efacd85893b03 100644 (file)
@@ -631,8 +631,8 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
     const auto permissionMap = job->property(propertyPermissionMap).toMap();
 
     QStringList sortedSubfolders = list;
-    // skip the parent item (first in the list)
-    sortedSubfolders.erase(sortedSubfolders.begin());
+    if (!sortedSubfolders.isEmpty())
+        sortedSubfolders.removeFirst(); // skip the parent item (first in the list)
     Utility::sortFilenames(sortedSubfolders);
 
     QVarLengthArray<int, 10> undecidedIndexes;