changeset 29174:4ca50ceb9576 stable

avoid crash due to accessing first element of empty list (bug #59656) * documentation.cc (documentation::load_ref): Avoid attempted access of first element of empty QList.
author John W. Eaton <jwe@octave.org>
date Fri, 11 Dec 2020 11:42:53 -0500
parents 32fdcf67a683
children 0ce474653a35 bd5961abe971
files libgui/src/documentation.cc
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/documentation.cc	Fri Dec 11 05:06:07 2020 -0500
+++ b/libgui/src/documentation.cc	Fri Dec 11 11:42:53 2020 -0500
@@ -632,23 +632,25 @@
     if (! m_help_engine || ref_name.isEmpty ())
       return;
 
-    // First search in the function index
 #if defined (HAVE_QHELPENGINE_DOCUMENTSFORIDENTIFIER)
     QList<QHelpLink> found_links
       = m_help_engine->documentsForIdentifier (ref_name);
-
-    QUrl first_url = found_links.constFirst().url;
 #else
     QMap<QString, QUrl> found_links
       = m_help_engine->linksForIdentifier (ref_name);
-
-    QUrl first_url = found_links.constBegin().value ();
 #endif
 
-      QTabWidget *navi = static_cast<QTabWidget*> (widget (0));
+    QTabWidget *navi = static_cast<QTabWidget*> (widget (0));
 
     if (found_links.count() > 0)
       {
+        // First search in the function index
+#if defined (HAVE_QHELPENGINE_DOCUMENTSFORIDENTIFIER)
+        QUrl first_url = found_links.constFirst().url;
+#else
+        QUrl first_url = found_links.constBegin().value ();
+#endif
+
         m_doc_browser->setSource (first_url);
 
         // Switch to function index tab