From c5d70c48c97c212c5e2982e363fa8f0033ab0ccc Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 26 Dec 2018 00:59:30 -0800 Subject: [PATCH] Fix QMap usage where insertion on read of missing value was not intended --- app/backend/computermanager.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/backend/computermanager.cpp b/app/backend/computermanager.cpp index f0370a49..03bfe6da 100644 --- a/app/backend/computermanager.cpp +++ b/app/backend/computermanager.cpp @@ -218,7 +218,7 @@ void ComputerManager::saveHosts() settings.beginWriteArray(SER_HOSTS); for (int i = 0; i < m_KnownHosts.count(); i++) { settings.setArrayIndex(i); - m_KnownHosts[m_KnownHosts.keys()[i]]->serialize(settings); + m_KnownHosts.value(m_KnownHosts.keys()[i])->serialize(settings); } settings.endArray(); } @@ -266,7 +266,7 @@ void ComputerManager::startPollingComputer(NvComputer* computer) } if (m_PollThreads.contains(computer->uuid)) { - Q_ASSERT(m_PollThreads[computer->uuid]->isRunning()); + Q_ASSERT(m_PollThreads.value(computer->uuid)->isRunning()); return; } @@ -324,9 +324,8 @@ public: { QWriteLocker lock(&m_ComputerManager->m_Lock); - pollingThread = m_ComputerManager->m_PollThreads[m_Computer->uuid]; + pollingThread = m_ComputerManager->m_PollThreads.take(m_Computer->uuid); - m_ComputerManager->m_PollThreads.remove(m_Computer->uuid); m_ComputerManager->m_KnownHosts.remove(m_Computer->uuid); } @@ -588,7 +587,7 @@ private: NvComputer* existingComputer; { QReadLocker lock(&m_ComputerManager->m_Lock); - existingComputer = m_ComputerManager->m_KnownHosts[newComputer->uuid]; + existingComputer = m_ComputerManager->m_KnownHosts.value(newComputer->uuid); if (existingComputer != nullptr) { http.setServerCert(existingComputer->serverCert); } @@ -627,7 +626,7 @@ private: { // Check if this PC already exists QWriteLocker lock(&m_ComputerManager->m_Lock); - NvComputer* existingComputer = m_ComputerManager->m_KnownHosts[newComputer->uuid]; + NvComputer* existingComputer = m_ComputerManager->m_KnownHosts.value(newComputer->uuid); if (existingComputer != nullptr) { // Fold it into the existing PC bool changed = existingComputer->update(*newComputer);