forked from qt-creator/qt-creator
Utils: Prevent crash when inserting into an empty environment model
Change-Id: Id857b21709d12534175a697625b3f5030f05fcd9 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -67,7 +67,8 @@ public:
|
||||
int findInResultInsertPosition(const QString &key) const
|
||||
{
|
||||
const auto compare = [](int compareResult) { return compareResult > 0; };
|
||||
return findIndex(m_resultNameValueDictionary, key, compare);
|
||||
const int pos = findIndex(m_resultNameValueDictionary, key, compare);
|
||||
return pos >= 0 ? pos : m_resultNameValueDictionary.size();
|
||||
}
|
||||
|
||||
int findInResult(const QString &key) const
|
||||
@@ -291,6 +292,7 @@ QModelIndex EnvironmentModel::addVariable(const EnvironmentItem &item)
|
||||
} else {
|
||||
// We add something that is not in the base dictionary
|
||||
// Insert a new line!
|
||||
QTC_ASSERT(insertPos >= 0, insertPos = d->m_resultNameValueDictionary.size());
|
||||
beginInsertRows(QModelIndex(), insertPos, insertPos);
|
||||
Q_ASSERT(changePos < 0);
|
||||
d->m_items.append(item);
|
||||
|
Reference in New Issue
Block a user