From f5d68d9c54f0c623bf34774d886e03dc3f3a048e Mon Sep 17 00:00:00 2001
From: dt <qtc-committer@nokia.com>
Date: Thu, 9 Dec 2010 20:08:10 +0100
Subject: [PATCH] EnvironmentModel: Fix crash on clicking add twice

Task-Nr: QTCREATORBUG-3336
---
 src/plugins/projectexplorer/environmenteditmodel.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/plugins/projectexplorer/environmenteditmodel.cpp b/src/plugins/projectexplorer/environmenteditmodel.cpp
index 3339927ca1a..b6b70badb68 100644
--- a/src/plugins/projectexplorer/environmenteditmodel.cpp
+++ b/src/plugins/projectexplorer/environmenteditmodel.cpp
@@ -291,14 +291,13 @@ QModelIndex EnvironmentModel::addVariable()
 
 QModelIndex EnvironmentModel::addVariable(const Utils::EnvironmentItem &item)
 {
-    int insertPos = findInResultInsertPosition(item.name);
 
     // Return existing index if the name is already in the result set:
-    if (insertPos < m_resultEnvironment.size()
-        && m_resultEnvironment.key(m_resultEnvironment.constBegin() + insertPos) == item.name) {
-        return index(insertPos, 0, QModelIndex());
-    }
+    int pos = findInResult(item.name);
+    if (pos < m_resultEnvironment.size())
+        return index(pos, 0, QModelIndex());
 
+    int insertPos = findInResultInsertPosition(item.name);
     int changePos = findInChanges(item.name);
     if (m_baseEnvironment.hasKey(item.name)) {
         // We previously unset this!
-- 
GitLab