Commit 2a78bb6e authored by Luis Javier Merino's avatar Luis Javier Merino Committed by Tomaz Canabrava
Browse files

Fix crash/warn on history reflow

When the last line in history was marked as wrapped, the history reflow
algorithm could try to make an out-of-bound access.

These were found via repeteadly zooming-in and out in the amp.rs editor
(available through Rust's cargo tool).  amp.rs writes in the normal
buffer (not in the alternate buffer).

While at it, add a Q_ASSERT in HistoryScrollFile::startOfLine() to
ensure parameters are in range.  Note that after an addCells()/addLine()
pair, HistoryScrollFile::startOfLine(getLines) always has the same value
as _cells.len().

BUG: 436916
parent 1d58aae6
......@@ -61,10 +61,12 @@ LineProperty HistoryScrollFile::getLineProperty(const int lineno) const
qint64 HistoryScrollFile::startOfLine(const int lineno) const
{
if (lineno <= 0) {
Q_ASSERT(lineno >= 0 && lineno <= getLines());
if (lineno == 0) {
return 0;
}
if (lineno <= getLines()) {
if (lineno < getLines()) {
qint64 res = 0;
_index.get(reinterpret_cast<char *>(&res), sizeof(qint64), (lineno - 1) * sizeof(qint64));
return res;
......@@ -127,7 +129,7 @@ int HistoryScrollFile::reflowLines(const int columns)
LineProperty lineProperty = getLineProperty(currentPos);
// Join the lines if they are wrapped
while (isWrappedLine(currentPos)) {
while (currentPos < getLines() - 1 && isWrappedLine(currentPos)) {
currentPos++;
endLine = startOfLine(currentPos + 1);
}
......
......@@ -150,7 +150,7 @@ int CompactHistoryScroll::reflowLines(const int columns)
LineProperty lineProperty = getLineProperty(currentPos);
// Join the lines if they are wrapped
while (isWrappedLine(currentPos)) {
while (currentPos < getLines() - 1 && isWrappedLine(currentPos)) {
currentPos++;
endLine = startOfLine(currentPos + 1);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment