From ad4208b0e61930ae7f45f89b59c4e13b1b2b421c Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Thu, 28 Jun 2007 19:03:26 +0000 Subject: [PATCH] Fix crash occurring when clearing the history when there was a view on the session which is not at the bottom. Add assertions to catch such errors earlier in future. svn path=/trunk/KDE/kdebase/apps/konsole/; revision=681379 --- src/Screen.cpp | 44 ++++++++++++++++++++++++-------------------- src/ScreenWindow.cpp | 4 ++++ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/Screen.cpp b/src/Screen.cpp index e1553d560..0fe1c834e 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -538,38 +538,38 @@ void Screen::effectiveRendition() Character* Screen::getCookedImage( int startLine ) { - int viewHistoryCursor = startLine; + Q_ASSERT( startLine <= hist->getLines() ); int x,y; Character* merged = new Character[lines*columns+1]; merged[lines*columns] = defaultChar; - for (y = 0; (y < lines) && (y < (hist->getLines()-viewHistoryCursor)); y++) + for (y = 0; (y < lines) && (y < (hist->getLines()-startLine)); y++) { - int len = qMin(columns,hist->getLineLen(y+viewHistoryCursor)); + int len = qMin(columns,hist->getLineLen(y+startLine)); int yp = y*columns; - hist->getCells(y+viewHistoryCursor,0,len,merged+yp); + hist->getCells(y+startLine,0,len,merged+yp); for (x = len; x < columns; x++) merged[yp+x] = defaultChar; if (sel_begin !=-1) for (x = 0; x < columns; x++) { #ifdef REVERSE_WRAPPED_LINES - if (hist->isLINE_WRAPPED(y+viewHistoryCursor)) + if (hist->isLINE_WRAPPED(y+startLine)) reverseRendition(&merged[p]); #endif - if (isSelected(x,y+viewHistoryCursor)) { + if (isSelected(x,y+startLine)) { int p=x + yp; reverseRendition(&merged[p]); // for selection } } } - if (lines >= hist->getLines()-viewHistoryCursor) + if (lines >= hist->getLines()-startLine) { - for (y = (hist->getLines()-viewHistoryCursor); y < lines ; y++) + for (y = (hist->getLines()-startLine); y < lines ; y++) { int yp = y*columns; - int yr = (y-hist->getLines()+viewHistoryCursor)*columns; + int yr = (y-hist->getLines()+startLine)*columns; for (x = 0; x < columns; x++) { int p = x + yp; int r = x + yr; @@ -580,10 +580,10 @@ Character* Screen::getCookedImage( int startLine ) merged[p] = screenLines[r/columns].value(r%columns,defaultChar); #ifdef REVERSE_WRAPPED_LINES - if (lineProperties[y- hist->getLines() +viewHistoryCursor] & LINE_WRAPPED) + if (lineProperties[y- hist->getLines() +startLine] & LINE_WRAPPED) reverseRendition(&merged[p]); #endif - if (sel_begin != -1 && isSelected(x,y+viewHistoryCursor)) + if (sel_begin != -1 && isSelected(x,y+startLine)) reverseRendition(&merged[p]); // for selection } @@ -595,34 +595,38 @@ Character* Screen::getCookedImage( int startLine ) for (int i = 0; i < lines*columns; i++) reverseRendition(&merged[i]); // for reverse display } -// if (getMode(MODE_Cursor) && (cuY+(hist->getLines()-viewHistoryCursor) < lines)) // cursor visible +// if (getMode(MODE_Cursor) && (cuY+(hist->getLines()-startLine) < lines)) // cursor visible - int loc_ = loc(cuX, cuY+hist->getLines()-viewHistoryCursor); + int loc_ = loc(cuX, cuY+hist->getLines()-startLine); if(getMode(MODE_Cursor) && loc_ < columns*lines) - merged[loc(cuX,cuY+(hist->getLines()-viewHistoryCursor))].rendition|=RE_CURSOR; + merged[loc(cuX,cuY+(hist->getLines()-startLine))].rendition|=RE_CURSOR; return merged; } QVector Screen::getCookedLineProperties( int startLine ) { - const int viewHistoryCursor = startLine; + Q_ASSERT( startLine <= hist->getLines() ); QVector result(lines); - for (int y = 0; (y < lines) && (y < (hist->getLines()-viewHistoryCursor)); y++) + // properties for lines in history + for (int y = 0; (y < lines) && (y < (hist->getLines()-startLine)); y++) { //TODO Support for line properties other than wrapped lines //result[y]=hist->isLINE_WRAPPED(y+viewHistoryCursor); - if (hist->isWrappedLine(y+viewHistoryCursor)) + if (hist->isWrappedLine(y+startLine)) { result[y] = (LineProperty)(result[y] | LINE_WRAPPED); } } - if (lines >= hist->getLines()-viewHistoryCursor) - for (int y = (hist->getLines()-viewHistoryCursor); y < lines ; y++) - result[y]=lineProperties[y- hist->getLines() +viewHistoryCursor]; + // properties for lines in screen buffer + if (lines >= hist->getLines()-startLine) + { + for (int y = (hist->getLines()-startLine); y < lines ; y++) + result[y]=lineProperties[y - hist->getLines() + startLine]; + } return result; } diff --git a/src/ScreenWindow.cpp b/src/ScreenWindow.cpp index c89202ea0..e63022f78 100644 --- a/src/ScreenWindow.cpp +++ b/src/ScreenWindow.cpp @@ -227,6 +227,10 @@ void ScreenWindow::notifyOutputChanged() // be adjusted - otherwise the output will scroll _currentLine = qMax(0,_currentLine - _screen->droppedLines()); + + // ensure that the screen window's current position does + // not go beyond the bottom of the screen + _currentLine = qMin( _currentLine , _screen->getHistLines() ); } emit outputChanged();