# HG changeset patch # User John W. Eaton # Date 1588913702 14400 # Node ID 86625d48831401174e65e0c6aff8c7e89c4a256d # Parent a36309586b0cd3e5398e773e20957e5a070f8a35 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. diff -r a36309586b0c -r 86625d488314 libgui/src/variable-editor-model.cc --- 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 (); }