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>
This commit is contained in:
Eike Ziller
2018-03-08 08:10:51 +01:00
parent 7ac1b852b7
commit 0bcc983cdb

View File

@@ -550,17 +550,16 @@ QRect BinEditorWidget::cursorRect() const
int BinEditorWidget::posAt(const QPoint &pos) 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 x = xoffset + pos.x() - m_margin - m_labelWidth;
int column = qMin(15, qMax(0,x) / m_columnWidth); int column = qMin(15, qMax(0,x) / m_columnWidth);
qint64 topLine = verticalScrollBar()->value(); const qint64 topLine = verticalScrollBar()->value();
qint64 line = pos.y() / m_lineHeight; const qint64 line = topLine + pos.y() / m_lineHeight;
if (x > m_bytesPerLine * m_columnWidth + m_charWidth/2) { if (x > m_bytesPerLine * m_columnWidth + m_charWidth/2) {
x -= m_bytesPerLine * m_columnWidth + m_charWidth; x -= m_bytesPerLine * m_columnWidth + m_charWidth;
for (column = 0; column < 15; ++column) { 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) if (dataPos < 0 || dataPos >= m_size)
break; break;
QChar qc(QLatin1Char(dataAt(dataPos))); 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 bool BinEditorWidget::inTextArea(const QPoint &pos) const