Use Q_ASSERT to catch null pointers for _sessionController and session()
ClosedPublic

Authored by ahmadsamir on Jun 1 2018, 3:57 PM.

Details

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.

Diff Detail

Repository
R319 Konsole
Branch
check-session-pointer (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
ahmadsamir created this revision.Jun 1 2018, 3:57 PM
Restricted Application added a project: Konsole. · View Herald TranscriptJun 1 2018, 3:57 PM
Restricted Application added a subscriber: konsole-devel. · View Herald Transcript
ahmadsamir requested review of this revision.Jun 1 2018, 3:57 PM
hindenburg added inline comments.
src/TerminalDisplay.cpp
798 ↗(On Diff #35353)

This is not quite the same - the previous checks _sessionController is not nullptr; this new doesn't.

ahmadsamir added inline comments.Jun 2 2018, 9:34 AM
src/TerminalDisplay.cpp
798 ↗(On Diff #35353)

Reflecting on this diff and the other one (about primaryScreen), if the session is null, checking for null won't really make a difference as the process is pretty much screwed with a TerminalDisplay but no associated SessionController or Session.

It makes more sense to add a Q_ASSERT() to catch this in debug builds; WDYT?

hindenburg added inline comments.Jun 5 2018, 12:17 PM
src/TerminalDisplay.cpp
798 ↗(On Diff #35353)

Ok that is fine

ahmadsamir updated this revision to Diff 35653.Jun 5 2018, 9:23 PM

Use Q_ASSERT instead of checking for nullptr

ahmadsamir updated this revision to Diff 35654.Jun 5 2018, 9:24 PM
ahmadsamir retitled this revision from Check that Session* isn't a nullptr to Use Q_ASSERT to catch null pointers for _sessionController and session().
ahmadsamir edited the summary of this revision. (Show Details)
ahmadsamir removed a subscriber: hindenburg.

Actually update the commit message

hindenburg added inline comments.Jun 6 2018, 12:13 PM
src/TerminalDisplay.cpp
798 ↗(On Diff #35353)

Don't we want the reverse? We want to die when the variable is nullptr, correct?

Prints a warning message containing the source code file name and line number if test is false.

ahmadsamir added inline comments.Jun 6 2018, 12:49 PM
src/TerminalDisplay.cpp
798 ↗(On Diff #35353)

You're right, of course. I'll fix it shortly.

ahmadsamir updated this revision to Diff 35686.Jun 6 2018, 2:58 PM

Fix Q_ASSERT condition.
Fix session()->isPrimaryScreen() condition.

ahmadsamir marked 5 inline comments as done.Jun 6 2018, 2:59 PM
hindenburg accepted this revision.Jun 7 2018, 2:49 PM
This revision is now accepted and ready to land.Jun 7 2018, 2:49 PM
This revision was automatically updated to reflect the committed changes.