changeset 28272:86625d488314 stable

avoid creating invalid model indices in variable editor (bug #58317) * variable-editor-model.cc (variable_editor_model::update_data): Don't emit dataChanged signal unless new_rows and new_cols are both greater than zero. (variable_editor_model::variable_editor_model): Don't attempt to insert columns (rows) unless the number of columns (rows) is greater than zero.
author John W. Eaton <jwe@octave.org>
date Fri, 08 May 2020 00:55:02 -0400
parents a36309586b0c
children 74af52e0e0fa 667bf684bb29
files libgui/src/variable-editor-model.cc
diffstat 1 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/variable-editor-model.cc	Thu May 07 11:11:35 2020 -0700
+++ b/libgui/src/variable-editor-model.cc	Fri May 08 00:55:02 2020 -0400
@@ -965,11 +965,21 @@
 
     if (is_editable ())
       {
-        beginInsertRows (QModelIndex (), 0, display_rows () - 1);
-        endInsertRows ();
+        int new_rows = display_rows ();
+
+        if (new_rows > 0)
+          {
+            beginInsertRows (QModelIndex (), 0, new_rows-1);
+            endInsertRows ();
+          }
 
-        beginInsertColumns (QModelIndex (), 0, display_columns () - 1);
-        endInsertColumns ();
+        int new_cols = display_columns ();
+
+        if (new_cols > 0)
+          {
+            beginInsertColumns (QModelIndex (), 0, new_cols-1);
+            endInsertColumns ();
+          }
       }
   }
 
@@ -1264,10 +1274,12 @@
       change_display_size (old_rows, old_cols, new_rows, new_cols);
 
     // Even if the size doesn't change, we still need to update here
-    // because the data may have changed.
+    // because the data may have changed.  But only if we have some data
+    // to display.
 
-    emit dataChanged (QAbstractTableModel::index (0, 0),
-                      QAbstractTableModel::index (new_rows-1, new_cols-1));
+    if (new_rows > 0 && new_cols > 0)
+      emit dataChanged (QAbstractTableModel::index (0, 0),
+                        QAbstractTableModel::index (new_rows-1, new_cols-1));
 
     clear_update_pending ();
   }