Commit eb6e7ded authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Make Workspace::outputAt() more robust to extreme values

Since QPointF can have values that exceed INT_MAX, "distance <
minDistance" may not be triggered for the first output.

In order to make Workspace::outputAt() more robust to such extreme
cases, this patch changes the type of minDistance from int to qreal to
avoid truncation and adds an explicit check to initialize bestOutput
when we see the first workspace output.

It would be also great to add size hints sanitization code in kwin, but
it can be done later.

BUG: 460446


Should close:


(cherry picked from commit 28899df4)
parent 44d3e436
Pipeline #249394 failed with stage
in 12 minutes and 56 seconds
......@@ -1390,7 +1390,8 @@ void Workspace::updateCurrentActivity(const QString &new_activity)
Output *Workspace::outputAt(const QPointF &pos) const
Output *bestOutput = nullptr;
int minDistance = INT_MAX;
qreal minDistance;
for (Output *output : std::as_const(m_outputs)) {
const QRect &geo = output->geometry();
if (geo.contains(pos.toPoint())) {
......@@ -1400,7 +1401,7 @@ Output *Workspace::outputAt(const QPointF &pos) const
distance = std::min(distance, QPointF(geo.topRight() - pos).manhattanLength());
distance = std::min(distance, QPointF(geo.bottomRight() - pos).manhattanLength());
distance = std::min(distance, QPointF(geo.bottomLeft() - pos).manhattanLength());
if (distance < minDistance) {
if (!bestOutput || distance < minDistance) {
minDistance = distance;
bestOutput = output;
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