diff --git a/src/libs/utils/historycompleter.cpp b/src/libs/utils/historycompleter.cpp
index 8ae061ca1bd72ca9e281f33a0ed034b40d54acc1..219c615395170f1b69eaac23b30cd9fead8272e8 100644
--- a/src/libs/utils/historycompleter.cpp
+++ b/src/libs/utils/historycompleter.cpp
@@ -129,8 +129,12 @@ QVariant HistoryCompleterPrivate::data(const QModelIndex &index, int role) const
 
 bool HistoryCompleterPrivate::removeRows(int row, int count, const QModelIndex &parent)
 {
-    beginRemoveRows (parent, row, row + count);
-    list.removeAt(row);
+    QTC_ASSERT(theSettings, return false);
+    if (row + count > list.count())
+        return false;
+    beginRemoveRows(parent, row, row + count -1);
+    for (int i = 0; i < count; ++i)
+        list.removeAt(row);
     theSettings->setValue(historyKey, list);
     endRemoveRows();
     return true;