From 6f96fab3652bb3602ac032ac443865fe40439dad Mon Sep 17 00:00:00 2001 From: Fushan Wen Date: Sat, 28 May 2022 14:58:37 +0800 Subject: [PATCH] Use `std::accumulate` in `ShellCorona::_availableScreenRegion` Consider using std::accumulate algorithm instead of a raw loop. (CWE-398) in shell/shellcorona.cpp:1051 --- shell/shellcorona.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/shell/shellcorona.cpp b/shell/shellcorona.cpp index acc86e6f0..4a6009eb3 100644 --- a/shell/shellcorona.cpp +++ b/shell/shellcorona.cpp @@ -1033,14 +1033,13 @@ QRegion ShellCorona::_availableScreenRegion(int id) const return s ? s->availableGeometry() : QRegion(); } - QRegion r = view->geometry(); - for (const PanelView *v : m_panelViews) { + return std::accumulate(m_panelViews.cbegin(), m_panelViews.cend(), QRegion(view->geometry()), [view](const QRegion &a, const PanelView *v) { if (v->isVisible() && view->screen() == v->screen() && v->visibilityMode() != PanelView::AutoHide) { // if the panel is being moved around, we still want to calculate it from the edge - r -= v->geometryByDistance(0); + return a - v->geometryByDistance(0); } - } - return r; + return a; + }); } QRect ShellCorona::availableScreenRect(int id) const