From 2898d63915e3bc3ad0e2008c99f364ec4115202b Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Wed, 4 Sep 2024 16:12:28 +0200 Subject: [PATCH] BinEditor: Check some optional values and use the non-throwing operator* Change-Id: Idddddf65ddea7fc269c672fced3d57ee55b0ded4 Reviewed-by: hjk --- src/plugins/bineditor/bineditorplugin.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/bineditor/bineditorplugin.cpp b/src/plugins/bineditor/bineditorplugin.cpp index d4c0a9acc26..09566d1b846 100644 --- a/src/plugins/bineditor/bineditorplugin.cpp +++ b/src/plugins/bineditor/bineditorplugin.cpp @@ -1262,8 +1262,11 @@ void BinEditorWidget::mousePressEvent(QMouseEvent *e) { if (e->button() != Qt::LeftButton) return; + const std::optional pos = posAt(e->pos()); + if (!pos) + return; MoveMode moveMode = e->modifiers() & Qt::ShiftModifier ? KeepAnchor : MoveAnchor; - setCursorPosition(posAt(e->pos()).value(), moveMode); + setCursorPosition(*pos, moveMode); setBlinkingCursorEnabled(true); if (m_hexCursor == inTextArea(e->pos())) { m_hexCursor = !m_hexCursor; @@ -1275,7 +1278,10 @@ void BinEditorWidget::mouseMoveEvent(QMouseEvent *e) { if (!(e->buttons() & Qt::LeftButton)) return; - setCursorPosition(posAt(e->pos()).value(), KeepAnchor); + const std::optional pos = posAt(e->pos()); + if (!pos) + return; + setCursorPosition(*pos, KeepAnchor); if (m_hexCursor == inTextArea(e->pos())) { m_hexCursor = !m_hexCursor; updateLines(); @@ -1397,7 +1403,7 @@ QString BinEditorWidget::toolTip(const QHelpEvent *helpEvent) const std::optional pos = posAt(helpEvent->pos(), /*includeEmptyArea*/false); if (!pos) return QString(); - selStart = pos.value(); + selStart = *pos; byteCount = 1; }