From 0bcc983cdbb74baebccfdb09f7d2ffb22ebf950d Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 8 Mar 2018 08:10:51 +0100 Subject: BinEditor: Fix that posAt could be larger than available bytes Task-number: QTCREATORBUG-17573 Change-Id: Ia34bb9b6765850937793d6481bb1e6404319d510 Reviewed-by: David Schulz --- src/plugins/bineditor/bineditorwidget.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/plugins/bineditor') diff --git a/src/plugins/bineditor/bineditorwidget.cpp b/src/plugins/bineditor/bineditorwidget.cpp index bb61571fb1..51d80a73c5 100644 --- a/src/plugins/bineditor/bineditorwidget.cpp +++ b/src/plugins/bineditor/bineditorwidget.cpp @@ -550,17 +550,16 @@ QRect BinEditorWidget::cursorRect() const int BinEditorWidget::posAt(const QPoint &pos) const { - int xoffset = horizontalScrollBar()->value(); + const int xoffset = horizontalScrollBar()->value(); int x = xoffset + pos.x() - m_margin - m_labelWidth; int column = qMin(15, qMax(0,x) / m_columnWidth); - qint64 topLine = verticalScrollBar()->value(); - qint64 line = pos.y() / m_lineHeight; - + const qint64 topLine = verticalScrollBar()->value(); + const qint64 line = topLine + pos.y() / m_lineHeight; if (x > m_bytesPerLine * m_columnWidth + m_charWidth/2) { x -= m_bytesPerLine * m_columnWidth + m_charWidth; for (column = 0; column < 15; ++column) { - int dataPos = (topLine + line) * m_bytesPerLine + column; + const int dataPos = line * m_bytesPerLine + column; if (dataPos < 0 || dataPos >= m_size) break; QChar qc(QLatin1Char(dataAt(dataPos))); @@ -572,7 +571,7 @@ int BinEditorWidget::posAt(const QPoint &pos) const } } - return qMin(m_size, qMin(m_numLines, topLine + line) * m_bytesPerLine) + column; + return qMin(m_size - 1, line * m_bytesPerLine + column); } bool BinEditorWidget::inTextArea(const QPoint &pos) const -- cgit v1.2.3