From cb4d52fb4cd689764994523f4bf9c60a6b274242 Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Wed, 1 Oct 2014 23:56:00 +0100 Subject: [PATCH] Fix infinit loop if component isn't found. Shell's CTOR will fail if Okular component isn't found, leading to i never being incremented. --- shell/okular_main.cpp | 9 +++++++++ shell/shell.cpp | 8 ++++++++ shell/shell.h | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/shell/okular_main.cpp b/shell/okular_main.cpp index 7f583ce9a..ef2a5de01 100644 --- a/shell/okular_main.cpp +++ b/shell/okular_main.cpp @@ -135,6 +135,11 @@ Status main(const QStringList &paths, const QString &serializedOptions) } Shell* shell = new Shell( serializedOptions ); + if ( !shell->isValid() ) + { + return Error; + } + shell->show(); for ( int i = 0; i < paths.count(); ) { @@ -147,6 +152,10 @@ Status main(const QStringList &paths, const QString &serializedOptions) else { shell = new Shell( serializedOptions ); + if ( !shell->isValid() ) + { + return Error; + } shell->show(); } } diff --git a/shell/shell.cpp b/shell/shell.cpp index c113e5717..f7675fdc8 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -64,6 +64,7 @@ Shell::Shell( const QString &serializedOptions ) #ifdef KActivities_FOUND , m_activityResource(0) #endif + , m_isValid(true) { setObjectName( QLatin1String( "okular::Shell" ) ); setContextMenuPolicy( Qt::NoContextMenu ); @@ -79,6 +80,7 @@ Shell::Shell( const QString &serializedOptions ) { // if we couldn't find our Part, we exit since the Shell by // itself can't do anything useful + m_isValid = false; KMessageBox::error(this, i18n("Unable to find the Okular component.")); return; } @@ -130,10 +132,16 @@ Shell::Shell( const QString &serializedOptions ) } else { + m_isValid = false; KMessageBox::error(this, i18n("Unable to find the Okular component.")); } } +bool Shell::isValid() const +{ + return m_isValid; +} + void Shell::showOpenRecentMenu() { m_recent->menu()->popup(QCursor::pos()); diff --git a/shell/shell.h b/shell/shell.h index 66788fa5a..224acfe02 100644 --- a/shell/shell.h +++ b/shell/shell.h @@ -60,6 +60,12 @@ public: virtual ~Shell(); QSize sizeHint() const; + + /** + * Returns false if Okular component wasn't found + **/ + bool isValid() const; + public slots: void slotQuit(); @@ -156,6 +162,7 @@ private: #ifdef KActivities_FOUND KActivities::ResourceInstance* m_activityResource; #endif + bool m_isValid; }; #endif