Skip to content

Commit

Permalink
fix nullptr deref in AudioFileProcessor (qt6 branch) (#7532)
Browse files Browse the repository at this point in the history
* ensured mouse event != nullptr before deref

* separation of concerns: AFP WaveView updateCursor

extract check to pointerCloseToStartEndOrLoop()

* marked some function parameters as const
  • Loading branch information
RiedleroD authored Oct 6, 2024
1 parent 16b9c2d commit f1c852b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
6 changes: 3 additions & 3 deletions include/DeprecationHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ inline int horizontalAdvance(const QFontMetrics& metrics, const QString& text)
* @param wheelEvent
* @return the position of wheelEvent
*/
inline QPoint position(QWheelEvent *wheelEvent)
inline QPoint position(const QWheelEvent *wheelEvent)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
return wheelEvent->position().toPoint();
Expand All @@ -70,7 +70,7 @@ inline QPoint position(QWheelEvent *wheelEvent)
* @param me
* @return the position of the mouse event
*/
inline QPoint position(QMouseEvent* me)
inline QPoint position(const QMouseEvent* me)
{
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
return me->position().toPoint();
Expand All @@ -85,7 +85,7 @@ inline QPoint position(QMouseEvent* me)
* @param me
* @return the position of the drop event
*/
inline QPoint position(QDropEvent* de)
inline QPoint position(const QDropEvent* de)
{
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
return de->position().toPoint();
Expand Down
22 changes: 14 additions & 8 deletions plugins/AudioFileProcessor/AudioFileProcessorWaveView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,24 +478,30 @@ void AudioFileProcessorWaveView::reverse()
m_reversed = ! m_reversed;
}

void AudioFileProcessorWaveView::updateCursor(QMouseEvent * me)
void AudioFileProcessorWaveView::updateCursor(const QMouseEvent * me)
{
const auto pos = position(me);

bool const waveIsDragged = m_isDragging && (m_draggingType == DraggingType::Wave);
bool const pointerCloseToStartEndOrLoop = (me != nullptr) &&
(isCloseTo(pos.x(), m_startFrameX) ||
isCloseTo(pos.x(), m_endFrameX) ||
isCloseTo(pos.x(), m_loopFrameX));

if (!m_isDragging && pointerCloseToStartEndOrLoop)
if (!m_isDragging && pointerCloseToStartEndOrLoop(me))
setCursor(Qt::SizeHorCursor);
else if (waveIsDragged)
setCursor(Qt::ClosedHandCursor);
else
setCursor(Qt::OpenHandCursor);
}

bool AudioFileProcessorWaveView::pointerCloseToStartEndOrLoop(const QMouseEvent * me) const
{
if (me == nullptr)
{
return false;
}

const QPoint pos = position(me);

return isCloseTo(pos.x(), m_startFrameX) || isCloseTo(pos.x(), m_endFrameX) || isCloseTo(pos.x(), m_loopFrameX);
}

void AudioFileProcessorWaveView::configureKnobRelationsAndWaveViews()
{
m_startKnob->setWaveView(this);
Expand Down
3 changes: 2 additions & 1 deletion plugins/AudioFileProcessor/AudioFileProcessorWaveView.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ public slots:

void updateGraph();
void reverse();
void updateCursor(QMouseEvent* me = nullptr);
void updateCursor(const QMouseEvent* me = nullptr);
bool pointerCloseToStartEndOrLoop(const QMouseEvent* me) const;

void configureKnobRelationsAndWaveViews();

Expand Down

0 comments on commit f1c852b

Please sign in to comment.