diff options
author | Eike Ziller <eike.ziller@qt.io> | 2018-03-08 08:10:51 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2018-03-13 08:54:07 +0000 |
commit | 0bcc983cdbb74baebccfdb09f7d2ffb22ebf950d (patch) | |
tree | bf2180bff687cbef28f502b3345daeb2c2ecf958 /src/plugins/bineditor | |
parent | 7ac1b852b75837c391ae06490b17037bf9ac7591 (diff) |
BinEditor: Fix that posAt could be larger than available bytes
Task-number: QTCREATORBUG-17573
Change-Id: Ia34bb9b6765850937793d6481bb1e6404319d510
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/bineditor')
-rw-r--r-- | src/plugins/bineditor/bineditorwidget.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
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 |