Просмотр исходного кода

Fix potential crash in restorePreviousVideoMode()

We did get a crash upload about it. And indeed, the display and/or mode
list can asynchronously change, making these IDs invalid. Verify them
before doing anything. The "correct" fix would probably be getting rid
of these IDs, but this will have to wait for later.

Also, the DisplayManager::isValid* methods erroneously accepted negative
IDs as valid, which is definitely wrong. (No, the QMap.size method does
not return an unsigned integer either.)
Vincent Lang 9 лет назад
Родитель
Сommit
b2e23d7c53
2 измененных файлов с 4 добавлено и 4 удалено
  1. 1 1
      src/display/DisplayComponent.cpp
  2. 3 3
      src/display/DisplayManager.cpp

+ 1 - 1
src/display/DisplayComponent.cpp

@@ -193,7 +193,7 @@ bool DisplayComponent::restorePreviousVideoMode()
   if (!m_displayManager)
     return false;
 
-  if (m_lastVideoMode < 0 || m_lastDisplay < 0)
+  if (!m_displayManager->isValidDisplayMode(m_lastDisplay, m_lastVideoMode))
     return false;
 
   bool ret = true;

+ 3 - 3
src/display/DisplayManager.cpp

@@ -61,13 +61,13 @@ DMVideoModePtr DisplayManager::getCurrentVideoMode(int display)
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-bool DisplayManager::isValidDisplay(int display) { return display < displays.size(); }
+bool DisplayManager::isValidDisplay(int display) { return display >= 0 && display < displays.size(); }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 bool DisplayManager::isValidDisplayMode(int display, int mode)
 {
-  if (display < displays.size())
-    if (displays[display]->videoModes.size() > mode)
+  if (isValidDisplay(display))
+    if (mode >= 0 && mode < displays[display]->videoModes.size())
       return true;
 
   return false;