# HG changeset patch # User Markus Mützel # Date 1669710484 -3600 # Tue Nov 29 09:28:04 2022 +0100 # Node ID 3ebddad34afd580e8a9ededfca92bdde6bb36ad3 # Parent 7a0702b1d19cf787c8b6fb59eef39a331903cdd7 gui: Check for potential nullptr of settings pointer in more places (bug #63437). * libgui/src/m-editor/file-editor-tab.cc: Check if the settings pointer is valid before dereferencing it. Use default values if it is invalid. diff -r 7a0702b1d19c -r 3ebddad34afd libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Mon Nov 28 19:56:21 2022 -0800 +++ b/libgui/src/m-editor/file-editor-tab.cc Tue Nov 29 09:28:04 2022 +0100 @@ -272,7 +272,9 @@ notice_settings (settings, true); // encoding, not updated with the settings - m_encoding = settings->value (ed_default_enc.key, "UTF-8").toString (); + m_encoding = settings + ? settings->value (ed_default_enc.key, "UTF-8").toString () + : "UTF-8"; m_enc_indicator->setText (m_encoding); // no changes in encoding yet m_new_encoding = m_encoding; @@ -743,9 +745,13 @@ // get settings which infos are used for octave bool octave_builtins - = settings->value (ed_code_completion_octave_builtins).toBool (); + = settings + ? settings->value (ed_code_completion_octave_builtins).toBool () + : true; bool octave_functions - = settings->value (ed_code_completion_octave_functions).toBool (); + = settings + ? settings->value (ed_code_completion_octave_functions).toBool () + : true; QCoreApplication::setApplicationName (tmp_app_name); // Restore name @@ -883,8 +889,12 @@ if (update_apis_only) return; // We are done here - int mode = settings->value (ed_color_mode).toInt (); - rmgr.read_lexer_settings (lexer, settings, mode); + int mode = 0; + if (settings) + { + mode = settings->value (ed_color_mode).toInt (); + rmgr.read_lexer_settings (lexer, settings, mode); + } m_edit_area->setCaretForegroundColor (lexer->color (0)); m_edit_area->setIndentationGuidesForegroundColor (lexer->color (0)); @@ -908,7 +918,9 @@ m_edit_area->setFoldMarginColors (bgm, fgm); QColor current_line_bg - = settings->color_value (ed_highlight_current_line_color, mode); + = settings + ? settings->color_value (ed_highlight_current_line_color, mode) + : settings_color_no_change; if (current_line_bg == settings_color_no_change) bgm = interpolate_color (bg, fg, 0.5, 0.1); // It is the "auto" color else @@ -923,7 +935,7 @@ // fix line number width with respect to the font size of the lexer and // set the line numbers font depending on the lexer's font - if (settings->value (ed_show_line_numbers).toBool ()) + if (settings && settings->value (ed_show_line_numbers).toBool ()) { // Line numbers width auto_margin_width (); @@ -1538,16 +1550,20 @@ resource_manager& rmgr = m_octave_qobj.get_resource_manager (); gui_settings *settings = rmgr.get_settings (); + QString last_comment = + settings + ? settings->value (ed_last_comment_str, comment_str.at (0)).toString () + : QString (); used_comment_str = QInputDialog::getText (this, tr ("Comment selected text"), tr ("Comment string to use:\n"), QLineEdit::Normal, - settings->value (ed_last_comment_str, comment_str.at (0)).toString (), + last_comment, &ok); if ((! ok) || used_comment_str.isEmpty ()) return; // No input, do nothing - else + else if (settings) settings->setValue (ed_last_comment_str, used_comment_str); // Store last } } @@ -1827,7 +1843,7 @@ resource_manager& rmgr = m_octave_qobj.get_resource_manager (); gui_settings *settings = rmgr.get_settings (); - if (settings->value (ed_force_newline).toBool ()) + if (settings && settings->value (ed_force_newline).toBool ()) { const QByteArray eol_lf = QByteArray (1, 0x0a); const QByteArray eol_cr = QByteArray (1, 0x0d); @@ -1971,7 +1987,9 @@ resource_manager& rmgr = m_octave_qobj.get_resource_manager (); gui_settings *settings = rmgr.get_settings (); QsciScintilla::EolMode eol_mode - = static_cast (settings->value (ed_default_eol_mode).toInt ()); + = settings + ? static_cast (settings->value (ed_default_eol_mode).toInt ()) + : QsciScintilla::EolUnix; int count_max = 0; @@ -2057,7 +2075,8 @@ // set the eol mode from the settings or depending on the OS if the entry is // missing in the settings - m_edit_area->setEolMode (static_cast (settings->value (ed_default_eol_mode).toInt ())); + if (settings) + m_edit_area->setEolMode (static_cast (settings->value (ed_default_eol_mode).toInt ())); update_eol_indicator (); @@ -2232,7 +2251,7 @@ resource_manager& rmgr = m_octave_qobj.get_resource_manager (); gui_settings *settings = rmgr.get_settings (); - if (settings->value (ed_rm_trailing_spaces).toBool ()) + if (settings && settings->value (ed_rm_trailing_spaces).toBool ()) { // Replace trailing spaces, make sure edit area is writable, // which is not the case when saving at exit or when closing @@ -2280,7 +2299,7 @@ QApplication::setOverrideCursor (Qt::WaitCursor); out << m_edit_area->text (); - if (settings->value (ed_force_newline).toBool () + if (settings && settings->value (ed_force_newline).toBool () && m_edit_area->text ().length ()) out << m_edit_area->eol_string (); // Add newline if desired @@ -2387,7 +2406,7 @@ // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. resource_manager& rmgr = m_octave_qobj.get_resource_manager (); gui_settings *settings = rmgr.get_settings (); - if (! settings->value (global_use_native_dialogs).toBool ()) + if (settings && ! settings->value (global_use_native_dialogs).toBool ()) { // Qt file dialogs fileDialog->setOption(QFileDialog::DontUseNativeDialog);