inputmgr: ensure we dont divide by zero (#6713)

some weird combination of scrolling/nesting hyprland and closing a
window i managed to divide by zero here, reported by ubsan. add a check
to ensure we dont hit UB.
This commit is contained in:
Tom Englund 2024-06-30 13:15:59 +02:00 committed by GitHub
parent 718afe271e
commit 8ff9410d2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -798,7 +798,7 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e) {
} }
} }
} }
double deltaDiscrete = factor * e.deltaDiscrete / std::abs(e.deltaDiscrete); double deltaDiscrete = (e.deltaDiscrete != 0) ? (factor * e.deltaDiscrete / std::abs(e.deltaDiscrete)) : 0;
g_pSeatManager->sendPointerAxis(e.timeMs, e.axis, factor * e.delta, deltaDiscrete > 0 ? std::ceil(deltaDiscrete) : std::floor(deltaDiscrete), g_pSeatManager->sendPointerAxis(e.timeMs, e.axis, factor * e.delta, deltaDiscrete > 0 ? std::ceil(deltaDiscrete) : std::floor(deltaDiscrete),
std::round(factor * e.deltaDiscrete), e.source, WL_POINTER_AXIS_RELATIVE_DIRECTION_IDENTICAL); std::round(factor * e.deltaDiscrete), e.source, WL_POINTER_AXIS_RELATIVE_DIRECTION_IDENTICAL);
} }