From ed6c1057cc9f4d933156d6ba9bad5ed55d62aabe Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Tue, 23 Jan 2007 15:05:10 +0000 Subject: [PATCH] Fix crash when making selections and add some safety checks. svn path=/branches/work/konsole-split-view/; revision=626511 --- konsole/SessionController.cpp | 30 +++++++++++++++++++++++++++++- konsole/SessionController.h | 34 ++++++++++++++++++++++++++++++++-- konsole/TEScreen.cpp | 24 ++++++++++++++++++++---- 3 files changed, 81 insertions(+), 7 deletions(-) diff --git a/konsole/SessionController.cpp b/konsole/SessionController.cpp index a037ca94..48c17512 100644 --- a/konsole/SessionController.cpp +++ b/konsole/SessionController.cpp @@ -24,6 +24,7 @@ // at the time of writing #include + KIcon SessionController::_activityIcon; KIcon SessionController::_silenceIcon; @@ -265,7 +266,7 @@ void SessionTask::addSession(TESession* session) { _sessions << session; } -QList SessionTask::sessions() const +QList SessionTask::sessions() const { return _sessions; } @@ -397,4 +398,31 @@ void SearchHistoryTask::execute() // not yet implemented } +SearchHistoryThread::SearchHistoryThread(SessionPtr session , QObject* parent) + : QThread(parent) + , _session(session) + , _lastLineFetched(-1) + , _decoder( new PlainTextDecoder() ) +{ +} + +SearchHistoryThread::~SearchHistoryThread() +{ + delete _decoder; +} + +void SearchHistoryThread::setRegExp(const QRegExp& expression) +{ + _regExp = expression; +} +QRegExp SearchHistoryThread::regExp() const +{ + return _regExp; +} + +void SearchHistoryThread::run() +{ + +} + #include "SessionController.moc" diff --git a/konsole/SessionController.h b/konsole/SessionController.h index 41908184..eb821ff9 100644 --- a/konsole/SessionController.h +++ b/konsole/SessionController.h @@ -6,6 +6,7 @@ #include #include #include +#include // KDE #include @@ -22,11 +23,14 @@ class UrlFilter; class TerminalCharacterDecoder; class KJob; + namespace KIO { class Job; }; +typedef QPointer SessionPtr; + /** * Provides the actions associated with a session in the Konsole main menu * and exposes information such as the title and icon associated with the session to view containers. @@ -143,7 +147,6 @@ signals: void completed(); protected: - typedef QPointer SessionPtr; /** Returns a list of sessions in the group */ QList< SessionPtr > sessions() const; @@ -196,6 +199,7 @@ private: QHash _jobSession; }; +class SearchHistoryThread; /** * A task which searches through the output of sessions for matches for a given regular expression. * @@ -234,8 +238,34 @@ signals: * @param endColumn The column in the output where the matched text ends */ void foundMatch(TESession* session , int startLine , int startColumn , int endLine , int endColumn ); - + +private: + + +private: + QRegExp _regExp; +}; + +class SearchHistoryThread : public QThread +{ +Q_OBJECT + +public: + SearchHistoryThread(SessionPtr session , QObject* parent); + virtual ~SearchHistoryThread(); + + void setRegExp(const QRegExp& expression); + QRegExp regExp() const; + +signals: + void foundMatch(TESession* session , int startLine , int startColumn , int endLine , int endColumn ); + +protected: + virtual void run(); private: + SessionPtr _session; + int _lastLineFetched; + TerminalCharacterDecoder* _decoder; QRegExp _regExp; }; diff --git a/konsole/TEScreen.cpp b/konsole/TEScreen.cpp index b96fceda..b2beb5d4 100644 --- a/konsole/TEScreen.cpp +++ b/konsole/TEScreen.cpp @@ -1375,16 +1375,30 @@ void TEScreen::copyLineToStream(int line , int start, int count, static ca characterBuffer[MAX_CHARS]; assert( count < MAX_CHARS ); - + //determine if the line is in the history buffer or the screen image if (line < hist->getLines()) { + const int lineLength = hist->getLineLen(line); + + // ensure that start position is before end of line + start = qMin(start,lineLength-1); + //retrieve line from history buffer if (count == -1) - count = hist->getLineLen(line)-start; + { + count = lineLength-start; + } else - count = qMin(start+count,hist->getLineLen(line))-start; - + { + count = qMin(start+count,lineLength)-start; + } + + // safety checks + assert( start >= 0 ); + assert( count >= 0 ); + assert( (start+count) <= hist->getLineLen(line) ); + hist->getCells(line,start,count,characterBuffer); } else @@ -1392,6 +1406,8 @@ void TEScreen::copyLineToStream(int line , int start, int count, if ( count == -1 ) count = columns - start; + assert( count >= 0 ); + ca* data = screenLines[line-hist->getLines()].data(); int length = screenLines[line-hist->getLines()].count();