From 85ee52b10fc5d53f8b36434e7ff691c70534dc79 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Wed, 6 Jun 2018 23:15:13 -0400 Subject: [PATCH] Use Q_ASSERT to catch null pointers for _sessionController and session() Summary: Remove TerminalDisplay::sessionIsPrimaryScreen(), and use Q_ASSERT instead, where if _sessionController is actually a nullptr it means the current konsole process is doomed anyway. Better catch such cases in debug builds. Reviewers: #konsole, hindenburg Reviewed By: #konsole, hindenburg Subscribers: konsole-devel, #konsole Tags: #konsole Differential Revision: https://phabricator.kde.org/D13271 --- src/TerminalDisplay.cpp | 33 +++++++++++++++------------------ src/TerminalDisplay.h | 5 ----- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp index a8ca41f2..db7e7de0 100644 --- a/src/TerminalDisplay.cpp +++ b/src/TerminalDisplay.cpp @@ -795,15 +795,16 @@ void TerminalDisplay::setCursorStyle(Enum::CursorShapeEnum shape, bool isBlinkin } void TerminalDisplay::resetCursorStyle() { - if (sessionController() != nullptr) { - Profile::Ptr currentProfile = SessionManager::instance()->sessionProfile(sessionController()->session()); + Q_ASSERT(_sessionController != nullptr); + Q_ASSERT(_sessionController->session() != nullptr); - if (currentProfile != nullptr) { - Enum::CursorShapeEnum shape = static_cast(currentProfile->property(Profile::CursorShape)); + Profile::Ptr currentProfile = SessionManager::instance()->sessionProfile(_sessionController->session()); - setKeyboardCursorShape(shape); - setBlinkingCursorEnabled(currentProfile->blinkingCursorEnabled()); - } + if (currentProfile != nullptr) { + Enum::CursorShapeEnum shape = static_cast(currentProfile->property(Profile::CursorShape)); + + setKeyboardCursorShape(shape); + setBlinkingCursorEnabled(currentProfile->blinkingCursorEnabled()); } } @@ -2834,12 +2835,17 @@ void TerminalDisplay::wheelEvent(QWheelEvent* ev) _scrollWheelState.addWheelEvent(ev); _scrollBar->event(ev); + + Q_ASSERT(_sessionController != nullptr); + _sessionController->setSearchStartToWindowCurrentLine(); _scrollWheelState.clearAll(); } else if (!_readOnly) { _scrollWheelState.addWheelEvent(ev); - if(!_usesMouseTracking && !sessionIsPrimaryScreen() && _alternateScrolling) { + Q_ASSERT(_sessionController->session() != nullptr); + + if(!_usesMouseTracking && !_sessionController->session()->isPrimaryScreen() && _alternateScrolling) { // Send simulated up / down key presses to the terminal program // for the benefit of programs such as 'less' (which use the alternate screen) @@ -2878,6 +2884,7 @@ void TerminalDisplay::wheelEvent(QWheelEvent* ev) void TerminalDisplay::viewScrolledByUser() { + Q_ASSERT(_sessionController != nullptr); _sessionController->setSearchStartToWindowCurrentLine(); } @@ -3870,16 +3877,6 @@ SessionController* TerminalDisplay::sessionController() return _sessionController; } -bool TerminalDisplay::sessionIsPrimaryScreen() -{ - Session *currentSession = _sessionController->session(); - if (currentSession !=nullptr) { - return currentSession->isPrimaryScreen(); - } - - return true; -} - AutoScrollHandler::AutoScrollHandler(QWidget* parent) : QObject(parent) , _timerId(0) diff --git a/src/TerminalDisplay.h b/src/TerminalDisplay.h index a331c176..ed90adf6 100644 --- a/src/TerminalDisplay.h +++ b/src/TerminalDisplay.h @@ -1037,11 +1037,6 @@ private: SessionController *_sessionController; - // Returns true if the screen buffer used in the current session is - // the primary/normal buffer or false if it's the alternate/secondary - // one - bool sessionIsPrimaryScreen(); - bool _trimLeadingSpaces; // trim leading spaces in selected text bool _trimTrailingSpaces; // trim trailing spaces in selected text bool _mouseWheelZoom; // enable mouse wheel zooming or not