Verified Commit c6b01d7f authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

shell: use `std::find_if` in `ShellCorona::setContainmentTypeForScreen`

Consider using std::find_if algorithm instead of a raw loop. (CWE-398)
in shell/shellcorona.cpp:1614
parent 470dcc51
Pipeline #182481 passed with stage
in 6 minutes and 16 seconds
......@@ -1573,16 +1573,12 @@ Plasma::Containment *ShellCorona::setContainmentTypeForScreen(int screen, const
return oldContainment;
}
DesktopView *view = nullptr;
for (DesktopView *v : qAsConst(m_desktopViewForScreen)) {
if (v->containment() == oldContainment) {
view = v;
break;
}
}
auto viewIt = std::find_if(m_desktopViewForScreen.cbegin(), m_desktopViewForScreen.cend(), [oldContainment](const DesktopView *v) {
return v->containment() == oldContainment;
});
// no view? give up
if (!view) {
if (viewIt == m_desktopViewForScreen.cend()) {
return oldContainment;
}
......@@ -1641,14 +1637,14 @@ Plasma::Containment *ShellCorona::setContainmentTypeForScreen(int screen, const
if (removeAction) {
removeAction->deleteLater();
}
view->setContainment(newContainment);
(*viewIt)->setContainment(newContainment);
newContainment->setActivity(oldContainment->activity());
insertContainment(oldContainment->activity(), screen, newContainment);
// removing the focus from the item that is going to be destroyed
// fixes a crash
// delayout the destruction of the old containment fixes another crash
view->rootObject()->setFocus(true, Qt::MouseFocusReason);
(*viewIt)->rootObject()->setFocus(true, Qt::MouseFocusReason);
QTimer::singleShot(2500, oldContainment, &Plasma::Applet::destroy);
// Save now as we now have a screen, so lastScreen will not be -1
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment