]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/selectionmode/backgroundcolorhelper.cpp
Fix potential nullptr de-reference
[dolphin.git] / src / selectionmode / backgroundcolorhelper.cpp
index 4477d0f2c1dedb4376067a934032f344acd47f0c..799db43d596dfe20a72f6365f55730e78bcb7d6e 100644 (file)
@@ -11,7 +11,6 @@
 
 #include <QGuiApplication>
 #include <QPalette>
-#include <QtGlobal>
 #include <QWidget>
 
 using namespace SelectionMode;
@@ -54,9 +53,11 @@ void BackgroundColorHelper::slotPaletteChanged()
 {
     updateBackgroundColor();
     for (auto i = m_colorControlledWidgets.begin(); i != m_colorControlledWidgets.end(); ++i) {
-        if (!*i) {
+        while (!*i) {
             i = m_colorControlledWidgets.erase(i);
-            continue;
+            if (i == m_colorControlledWidgets.end()) {
+                return;
+            }
         }
         setBackgroundColorForWidget(*i, m_backgroundColor);
     }
@@ -83,7 +84,8 @@ void BackgroundColorHelper::updateBackgroundColor()
     }
 
     m_backgroundColor = QColor::fromHsv(newHue,
-                                        // Saturation should be closer to the active color because otherwise the selection mode color might overpower it.
+                                        // Saturation should be closer to the saturation of the active color
+                                        // because otherwise the selection mode color might overpower it.
                                         .7 * activeBackgroundColor.saturation() + .3 * positiveBackgroundColor.saturation(),
                                         (activeBackgroundColor.value() + positiveBackgroundColor.value()) / 2,
                                         (activeBackgroundColor.alpha() + positiveBackgroundColor.alpha()) / 2);