Skip to content

Commit

Permalink
do not use static_cast to downcast: can generate runtime issues
Browse files Browse the repository at this point in the history
using a static_cast like this means that the compiler will not check the
validity of the cast

this could lead now or later to crash and other issues if the real type
is not the one in the cast

done with clang-tidy

run-clang-tidy -p build -header-filter='.*' -config="{Checks: '*', CheckOptions: [{key: UseAssignment, value: true}]}" -checks='-*,cppcoreguidelines-pro-type-static-cast-downcast' -fix

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
  • Loading branch information
mgallien committed Feb 21, 2023
1 parent 5b048aa commit 9390b7d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/3rdparty/kirigami/wheelhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ bool WheelHandler::eventFilter(QObject *watched, QEvent *event)
m_horizontalScrollBar->setProperty("interactive", true);
}
}
auto *wheelEvent = static_cast<QWheelEvent *>(event);
auto *wheelEvent = dynamic_cast<QWheelEvent *>(event);

// NOTE: On X11 with libinput, pixelDelta is identical to angleDelta when using a mouse that shouldn't use pixelDelta.
// If faulty pixelDelta, reset pixelDelta to (0,0).
Expand Down Expand Up @@ -555,7 +555,7 @@ bool WheelHandler::eventFilter(QObject *watched, QEvent *event)

case QEvent::MouseButtonPress: {
// NOTE: Flickable does not handle touch events, only synthesized mouse events
m_wasTouched = static_cast<QMouseEvent *>(event)->source() != Qt::MouseEventNotSynthesized;
m_wasTouched = dynamic_cast<QMouseEvent *>(event)->source() != Qt::MouseEventNotSynthesized;
if (!m_filterMouseEvents) {
break;
}
Expand All @@ -577,7 +577,7 @@ bool WheelHandler::eventFilter(QObject *watched, QEvent *event)
if (!m_filterMouseEvents) {
break;
}
if (static_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized && item == m_flickable) {
if (dynamic_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized && item == m_flickable) {
return true;
}
break;
Expand All @@ -603,7 +603,7 @@ bool WheelHandler::eventFilter(QObject *watched, QEvent *event)
if (!m_keyNavigationEnabled) {
break;
}
auto *keyEvent = static_cast<QKeyEvent *>(event);
auto *keyEvent = dynamic_cast<QKeyEvent *>(event);
bool horizontalScroll = keyEvent->modifiers() & m_defaultHorizontalScrollModifiers;
switch (keyEvent->key()) {
case Qt::Key_Up: return scrollUp();
Expand Down

0 comments on commit 9390b7d

Please sign in to comment.