# HG changeset patch # User John W. Eaton # Date 1711210799 14400 # Node ID 39b6d6ca38316e0a2beb88c448c3fe644d79adad # Parent 5565b3e6eb60efaefdb4e93b74d4401934f2b59b# Parent 4e5bc9c4f6572c20c1a52745e71ca5ebba17fafe maint: merge default to bytecode-interpreter diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/graphics/ButtonGroup.cc --- a/libgui/graphics/ButtonGroup.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/graphics/ButtonGroup.cc Sat Mar 23 12:19:59 2024 -0400 @@ -179,7 +179,7 @@ frame->hide (); connect (m_buttongroup, - QOverload::of (&QButtonGroup::buttonClicked), + qOverload (&QButtonGroup::buttonClicked), this, &ButtonGroup::buttonClicked); } diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/graphics/Container.cc --- a/libgui/graphics/Container.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/graphics/Container.cc Sat Mar 23 12:19:59 2024 -0400 @@ -69,11 +69,11 @@ m_canvas = Canvas::create (m_interpreter, gh, this, fig.get ("renderer").string_value ()); - connect (m_canvas, QOverload::of (&Canvas::interpreter_event), - this, QOverload::of (&Container::interpreter_event)); + connect (m_canvas, qOverload (&Canvas::interpreter_event), + this, qOverload (&Container::interpreter_event)); - connect (m_canvas, QOverload::of (&Canvas::interpreter_event), - this, QOverload::of (&Container::interpreter_event)); + connect (m_canvas, qOverload (&Canvas::interpreter_event), + this, qOverload (&Container::interpreter_event)); connect (m_canvas, SIGNAL (gh_callback_event (const graphics_handle&, diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/graphics/Figure.cc --- a/libgui/graphics/Figure.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/graphics/Figure.cc Sat Mar 23 12:19:59 2024 -0400 @@ -122,11 +122,11 @@ m_container = new Container (win, interp); win->setCentralWidget (m_container); - connect (m_container, QOverload::of (&Container::interpreter_event), - this, QOverload::of (&Figure::interpreter_event)); + connect (m_container, qOverload (&Container::interpreter_event), + this, qOverload (&Figure::interpreter_event)); - connect (m_container, QOverload::of (&Container::interpreter_event), - this, QOverload::of (&Figure::interpreter_event)); + connect (m_container, qOverload (&Container::interpreter_event), + this, qOverload (&Figure::interpreter_event)); figure::properties& fp = properties
(); diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/graphics/PopupMenuControl.cc --- a/libgui/graphics/PopupMenuControl.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/graphics/PopupMenuControl.cc Sat Mar 23 12:19:59 2024 -0400 @@ -64,7 +64,7 @@ update (uicontrol::properties::ID_VALUE); - connect (box, QOverload::of (&QComboBox::activated), + connect (box, qOverload (&QComboBox::activated), this, &PopupMenuControl::currentIndexChanged); } diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/src/command-widget.cc --- a/libgui/src/command-widget.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/src/command-widget.cc Sat Mar 23 12:19:59 2024 -0400 @@ -90,11 +90,11 @@ connect (this, &command_widget::new_command_line_signal, m_console, &console::new_command_line); - connect (m_console, QOverload::of (&console::interpreter_event), - this, QOverload::of (&command_widget::interpreter_event)); + connect (m_console, qOverload (&console::interpreter_event), + this, qOverload (&command_widget::interpreter_event)); - connect (m_console, QOverload::of (&console::interpreter_event), - this, QOverload::of (&command_widget::interpreter_event)); + connect (m_console, qOverload (&console::interpreter_event), + this, qOverload (&command_widget::interpreter_event)); insert_interpreter_output ("\n\n Welcome to Octave\n\n"); diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/src/documentation-bookmarks.cc --- a/libgui/src/documentation-bookmarks.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/src/documentation-bookmarks.cc Sat Mar 23 12:19:59 2024 -0400 @@ -340,7 +340,7 @@ } menu.addAction (tr ("&Add Folder"), this, - QOverload::of (&documentation_bookmarks::add_folder)); + qOverload (&documentation_bookmarks::add_folder)); menu.addSeparator (); diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/src/m-editor/file-editor-tab.cc Sat Mar 23 12:19:59 2024 -0400 @@ -232,11 +232,11 @@ // Any interpreter_event signal from a file_editor_tab_widget is // handled the same as for the parent main_window object. - connect (m_edit_area, QOverload::of (&octave_qscintilla::interpreter_event), - this, QOverload::of (&file_editor_tab::interpreter_event)); - - connect (m_edit_area, QOverload::of (&octave_qscintilla::interpreter_event), - this, QOverload::of (&file_editor_tab::interpreter_event)); + connect (m_edit_area, qOverload (&octave_qscintilla::interpreter_event), + this, qOverload (&file_editor_tab::interpreter_event)); + + connect (m_edit_area, qOverload (&octave_qscintilla::interpreter_event), + this, qOverload (&file_editor_tab::interpreter_event)); // connect modified signal connect (m_edit_area, SIGNAL (modificationChanged (bool)), diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/src/m-editor/file-editor.cc Sat Mar 23 12:19:59 2024 -0400 @@ -2629,8 +2629,8 @@ connect (this, &file_editor::fetab_change_request, f, &file_editor_tab::change_editor_state); - connect (this, QOverload::of (&file_editor::fetab_save_file), - f, QOverload::of (&file_editor_tab::save_file)); + connect (this, qOverload (&file_editor::fetab_save_file), + f, qOverload (&file_editor_tab::save_file)); // Signals from the file_editor trivial operations connect (this, &file_editor::fetab_recover_from_exit, @@ -2652,11 +2652,11 @@ connect (this, &file_editor::fetab_context_edit, f, &file_editor_tab::context_edit); - connect (this, QOverload::of (&file_editor::fetab_save_file), - f, QOverload::of (&file_editor_tab::save_file)); + connect (this, qOverload (&file_editor::fetab_save_file), + f, qOverload (&file_editor_tab::save_file)); connect (this, &file_editor::fetab_save_file_as, - f, QOverload::of (&file_editor_tab::save_file_as)); + f, qOverload (&file_editor_tab::save_file_as)); connect (this, &file_editor::fetab_print_file, f, &file_editor_tab::print_file); @@ -2756,11 +2756,11 @@ // Any interpreter_event signal from a file_editor_tab_widget is // handled the same as for the parent main_window object. - connect (f, QOverload::of (&file_editor_tab::interpreter_event), - this, QOverload::of (&file_editor::interpreter_event)); - - connect (f, QOverload::of (&file_editor_tab::interpreter_event), - this, QOverload::of (&file_editor::interpreter_event)); + connect (f, qOverload (&file_editor_tab::interpreter_event), + this, qOverload (&file_editor::interpreter_event)); + + connect (f, qOverload (&file_editor_tab::interpreter_event), + this, qOverload (&file_editor::interpreter_event)); return f; } diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/src/main-window.cc --- a/libgui/src/main-window.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/src/main-window.cc Sat Mar 23 12:19:59 2024 -0400 @@ -258,7 +258,7 @@ this, &main_window::edit_mfile); connect (cmd_widget, &QTerminal::request_open_file_signal, - this, QOverload::of (&main_window::open_file_signal)); + this, qOverload (&main_window::open_file_signal)); connect (cmd_widget, &QTerminal::set_screen_size_signal, this, &main_window::set_screen_size); @@ -289,7 +289,7 @@ make_dock_widget_connections (m_file_browser_window); connect (m_file_browser_window, &files_dock_widget::open_file, - this, QOverload::of (&main_window::open_file_signal)); + this, qOverload (&main_window::open_file_signal)); connect (m_file_browser_window, &files_dock_widget::displayed_directory_changed, this, &main_window::set_current_working_directory); @@ -357,7 +357,7 @@ &workspace_model::show_symbol_tooltip); connect (editor, &file_editor::request_settings_dialog, - this, QOverload::of (&main_window::process_settings_dialog_request)); + this, qOverload (&main_window::process_settings_dialog_request)); connect (editor, &file_editor::request_dbcont_signal, this, &main_window::debug_continue); @@ -1894,11 +1894,11 @@ // Any interpreter_event signal from a set_path_dialog object is // handled the same as for the main_window object. - connect (m_set_path_dlg, QOverload::of (&set_path_dialog::interpreter_event), - this, QOverload::of (&main_window::interpreter_event)); - - connect (m_set_path_dlg, QOverload::of (&set_path_dialog::interpreter_event), - this, QOverload::of (&main_window::interpreter_event)); + connect (m_set_path_dlg, qOverload (&set_path_dialog::interpreter_event), + this, qOverload (&main_window::interpreter_event)); + + connect (m_set_path_dlg, qOverload (&set_path_dialog::interpreter_event), + this, qOverload (&main_window::interpreter_event)); connect (m_set_path_dlg, &set_path_dialog::modify_path_signal, this, &main_window::modify_path); @@ -1931,7 +1931,7 @@ m_file_browser_window, &files_dock_widget::set_current_directory); connect (m_find_files_dlg, &find_files_dialog::file_selected, - this, QOverload::of (&main_window::open_file_signal)); + this, qOverload (&main_window::open_file_signal)); m_find_files_dlg->setWindowModality (Qt::NonModal); } @@ -2166,11 +2166,11 @@ connect (qt_link, &qt_interpreter_events::file_remove_signal, this, &main_window::file_remove_proxy); - connect (this, QOverload::of (&main_window::interpreter_event), - &m_octave_qobj, QOverload::of (&base_qobject::interpreter_event)); - - connect (this, QOverload::of (&main_window::interpreter_event), - &m_octave_qobj, QOverload::of (&base_qobject::interpreter_event)); + connect (this, qOverload (&main_window::interpreter_event), + &m_octave_qobj, qOverload (&base_qobject::interpreter_event)); + + connect (this, qOverload (&main_window::interpreter_event), + &m_octave_qobj, qOverload (&base_qobject::interpreter_event)); configure_shortcuts (); } diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/src/octave-qobject.cc --- a/libgui/src/octave-qobject.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/src/octave-qobject.cc Sat Mar 23 12:19:59 2024 -0400 @@ -239,11 +239,11 @@ // Handle any interpreter_event signal from the octave_qapplication // object here. - connect (m_qapplication, QOverload::of (&octave_qapplication::interpreter_event), - this, QOverload::of (&base_qobject::interpreter_event)); + connect (m_qapplication, qOverload (&octave_qapplication::interpreter_event), + this, qOverload (&base_qobject::interpreter_event)); - connect (m_qapplication, QOverload::of (&octave_qapplication::interpreter_event), - this, QOverload::of (&base_qobject::interpreter_event)); + connect (m_qapplication, qOverload (&octave_qapplication::interpreter_event), + this, qOverload (&base_qobject::interpreter_event)); if (m_app_context.experimental_terminal_widget ()) { diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/src/octave-qobject.h --- a/libgui/src/octave-qobject.h Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/src/octave-qobject.h Sat Mar 23 12:19:59 2024 -0400 @@ -194,11 +194,11 @@ template void connect_interpreter_events (T *widget) { - connect (widget, QOverload::of (&T::interpreter_event), - this, QOverload::of (&base_qobject::interpreter_event)); + connect (widget, qOverload (&T::interpreter_event), + this, qOverload (&base_qobject::interpreter_event)); - connect (widget, QOverload::of (&T::interpreter_event), - this, QOverload::of (&base_qobject::interpreter_event)); + connect (widget, qOverload (&T::interpreter_event), + this, qOverload (&base_qobject::interpreter_event)); } public slots: diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/src/set-path-dialog.cc --- a/libgui/src/set-path-dialog.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/src/set-path-dialog.cc Sat Mar 23 12:19:59 2024 -0400 @@ -120,11 +120,11 @@ // Any interpreter_event signal from a set_path_model object is // handled the same as for the parent set_path_dialog object. - connect (model, QOverload::of (&set_path_model::interpreter_event), - this, QOverload::of (&set_path_dialog::interpreter_event)); + connect (model, qOverload (&set_path_model::interpreter_event), + this, qOverload (&set_path_dialog::interpreter_event)); - connect (model, QOverload::of (&set_path_model::interpreter_event), - this, QOverload::of (&set_path_dialog::interpreter_event)); + connect (model, qOverload (&set_path_model::interpreter_event), + this, qOverload (&set_path_dialog::interpreter_event)); m_path_list = new QListView (this); m_path_list->setWordWrap (false); diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/src/settings-dialog.cc --- a/libgui/src/settings-dialog.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/src/settings-dialog.cc Sat Mar 23 12:19:59 2024 -0400 @@ -437,7 +437,7 @@ { proxy_type->addItems (global_proxy_all_types); // Connect relevant signals for dis-/enabling some elements - connect (proxy_type, QOverload::of (&QComboBox::currentIndexChanged), + connect (proxy_type, qOverload (&QComboBox::currentIndexChanged), this, &settings_dialog::proxy_items_update); connect (use_proxy_server, &QCheckBox::toggled, this, &settings_dialog::proxy_items_update); diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/src/terminal-dock-widget.cc --- a/libgui/src/terminal-dock-widget.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/src/terminal-dock-widget.cc Sat Mar 23 12:19:59 2024 -0400 @@ -92,11 +92,11 @@ connect (this, &terminal_dock_widget::visibilityChanged, widget, &QTerminal::handle_visibility_changed); - connect (widget, QOverload::of (&QTerminal::interpreter_event), - this, QOverload::of (&terminal_dock_widget::interpreter_event)); + connect (widget, qOverload (&QTerminal::interpreter_event), + this, qOverload (&terminal_dock_widget::interpreter_event)); - connect (widget, QOverload::of (&QTerminal::interpreter_event), - this, QOverload::of (&terminal_dock_widget::interpreter_event)); + connect (widget, qOverload (&QTerminal::interpreter_event), + this, qOverload (&terminal_dock_widget::interpreter_event)); m_terminal = widget; } diff -r 5565b3e6eb60 -r 39b6d6ca3831 libgui/src/variable-editor.cc --- a/libgui/src/variable-editor.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libgui/src/variable-editor.cc Sat Mar 23 12:19:59 2024 -0400 @@ -1297,11 +1297,11 @@ // Any interpreter_event signal from a variable_editor_stack object is // handled the same as for the parent variable_editor object. - connect (stack, QOverload::of (&variable_editor_stack::interpreter_event), - this, QOverload::of (&variable_editor::interpreter_event)); + connect (stack, qOverload (&variable_editor_stack::interpreter_event), + this, qOverload (&variable_editor::interpreter_event)); - connect (stack, QOverload::of (&variable_editor_stack::interpreter_event), - this, QOverload::of (&variable_editor::interpreter_event)); + connect (stack, qOverload (&variable_editor_stack::interpreter_event), + this, qOverload (&variable_editor::interpreter_event)); connect (stack, &variable_editor_stack::edit_variable_signal, this, &variable_editor::edit_variable); @@ -1373,11 +1373,11 @@ // Any interpreter_event signal from a variable_editor_model object is // handled the same as for the parent variable_editor object. - connect (model, QOverload::of (&variable_editor_model::interpreter_event), - this, QOverload::of (&variable_editor::interpreter_event)); + connect (model, qOverload (&variable_editor_model::interpreter_event), + this, qOverload (&variable_editor::interpreter_event)); - connect (model, QOverload::of (&variable_editor_model::interpreter_event), - this, QOverload::of (&variable_editor::interpreter_event)); + connect (model, qOverload (&variable_editor_model::interpreter_event), + this, qOverload (&variable_editor::interpreter_event)); // Must supply a title for a QLabel to be created. Calling set_title() // more than once will add more QLabels. Could change octave_dock_widget diff -r 5565b3e6eb60 -r 39b6d6ca3831 libinterp/corefcn/debug.cc --- a/libinterp/corefcn/debug.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libinterp/corefcn/debug.cc Sat Mar 23 12:19:59 2024 -0400 @@ -592,6 +592,69 @@ return ovl (); } +static bool +parse_start_end (const std::string& arg, int& start, int& end, const char *who) +{ + start = 0; + end = 0; + + std::size_t ind = arg.find (':'); + + if (ind != std::string::npos) // (start:end) + { + std::string start_str = arg.substr (0, ind); + std::string end_str = arg.substr (ind+1); + + try + { + start = std::stoi (start_str); + + if (end_str == "end") + end = std::numeric_limits::max (); + else + end = std::stoi (end_str); + } + catch (const std::invalid_argument&) + { + error ("%s: invalid integer conversion while parsing range '%s'", who, arg.c_str ()); + } + catch (const std::out_of_range&) + { + error ("%s: integer value out of bounds while parsing range '%s'", who, arg.c_str ()); + } + + if (std::min (start, end) <= 0) + error ("%s: start and end lines must be >= 1\n", who); + + if (start > end) + error ("%s: start line must be less than end line\n", who); + } + else // (dbtype lineno) + { + try + { + int line = std::stoi (arg); + + if (line <= 0) + error ("%s: start and end lines must be >= 1\n", who); + + start = line; + end = line; + } + catch (const std::invalid_argument&) + { + // May be a name instead of a number. + return false; + } + catch (const std::out_of_range&) + { + error ("%s: integer value out of bounds while parsing '%s'", who, arg.c_str ()); + } + } + + return true; +} + DEFMETHOD (dbtype, interp, args, , doc: /* -*- texinfo -*- @deftypefn {} {} dbtype @@ -633,40 +696,8 @@ { std::string arg = argv[1]; - std::size_t ind = arg.find (':'); - - if (ind != std::string::npos) // (dbtype start:end) - { - std::string start_str = arg.substr (0, ind); - std::string end_str = arg.substr (ind + 1); - - start = atoi (start_str.c_str ()); - if (end_str == "end") - end = std::numeric_limits::max (); - else - end = atoi (end_str.c_str ()); - - if (std::min (start, end) <= 0) - error ("dbtype: start and end lines must be >= 1\n"); - - if (start > end) - error ("dbtype: start line must be less than end line\n"); - } - else // (dbtype fcn) || (dbtype lineno) - { - int line = atoi (arg.c_str ()); - - if (line == 0) // (dbtype fcn) - fcn_name = arg; - else // (dbtype lineno) - { - if (line <= 0) - error ("dbtype: start and end lines must be >= 1\n"); - - start = line; - end = line; - } - } + if (! parse_start_end (arg, start, end, "dbtype")) + fcn_name = arg; } break; @@ -674,31 +705,8 @@ { fcn_name = argv[1]; - std::string arg = argv[2]; - std::size_t ind = arg.find (':'); - - if (ind != std::string::npos) - { - std::string start_str = arg.substr (0, ind); - std::string end_str = arg.substr (ind + 1); - - start = atoi (start_str.c_str ()); - if (end_str == "end") - end = std::numeric_limits::max (); - else - end = atoi (end_str.c_str ()); - } - else - { - start = atoi (arg.c_str ()); - end = start; - } - - if (std::min (start, end) <= 0) - error ("dbtype: start and end lines must be >= 1\n"); - - if (start > end) - error ("dbtype: start line must be less than end line\n"); + if (! parse_start_end (argv[2], start, end, "dbtype")) + error ("dbtype: expecting start:end or location argument, found '%s'", argv[2].c_str ()); } break; @@ -725,6 +733,27 @@ return ovl (); } +static int +parse_integer_argument (const std::string& arg, const char *who) +{ + int n = 0; + + try + { + n = std::stoi (arg); + } + catch (const std::invalid_argument&) + { + error ("%s: invalid value of N, found '%s'", arg.c_str (), who); + } + catch (const std::out_of_range&) + { + error ("%s: value of N ('%s') is out of range", arg.c_str (), who); + } + + return n; +} + DEFMETHOD (dblist, interp, args, , doc: /* -*- texinfo -*- @deftypefn {} {} dblist @@ -748,11 +777,7 @@ octave_value arg = args(0); if (arg.is_string ()) - { - std::string s_arg = arg.string_value (); - - n = atoi (s_arg.c_str ()); - } + n = parse_integer_argument (arg.string_value (), "dblist"); else n = args(0).int_value (); @@ -798,7 +823,7 @@ if (s_arg == "-completenames") continue; - n = atoi (s_arg.c_str ()); + n = parse_integer_argument (s_arg, "dbstack"); } else n = arg.int_value (); @@ -944,11 +969,7 @@ octave_value arg = args(0); if (arg.is_string ()) - { - std::string s_arg = arg.string_value (); - - n = atoi (s_arg.c_str ()); - } + n = parse_integer_argument (arg.string_value (), who.c_str ()); else n = args(0).int_value (); } @@ -1038,10 +1059,10 @@ n = -2; else { - n = atoi (arg.c_str ()); + n = parse_integer_argument (arg, "dbstep"); if (n < 1) - error ("dbstep: invalid argument"); + error ("dbstep: N must be greater than zero"); } } else diff -r 5565b3e6eb60 -r 39b6d6ca3831 libinterp/corefcn/event-manager.cc --- a/libinterp/corefcn/event-manager.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libinterp/corefcn/event-manager.cc Sat Mar 23 12:19:59 2024 -0400 @@ -362,7 +362,19 @@ if (idx != 2) retval(idx++) = str; else - retval(idx++) = atoi (str.c_str ()); + { + // FIXME: Should we warn or error on invalid or out of + // range values in STR? When atoi was used for + // conversion instead of std::stoi we did not. Was + // that intentional? + + try + { + retval(idx++) = std::stoi (str); + } + catch (const std::invalid_argument&) { } + catch (const std::out_of_range&) { } + } } } } @@ -377,7 +389,22 @@ for (int idx = 0; idx < nel; idx++, it++) items.xelem (idx) = *it; - retval = ovl (items, *it++, atoi (it->c_str ())); + auto fpath = *it++; + + int idx = 0; + + // FIXME: Should we warn or error on invalid or out of range + // values in *IT? When atoi was used for conversion instead of + // std::stoi we did not. Was that intentional? + + try + { + idx = std::stoi (*it); + } + catch (const std::invalid_argument&) { } + catch (const std::out_of_range&) { } + + retval = ovl (items, fpath, idx); } return retval; diff -r 5565b3e6eb60 -r 39b6d6ca3831 libinterp/corefcn/syscalls.cc --- a/libinterp/corefcn/syscalls.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libinterp/corefcn/syscalls.cc Sat Mar 23 12:19:59 2024 -0400 @@ -485,7 +485,7 @@ if (status < 0) retval = ovl (-1.0, msg); else - retval = ovl (0.0, ""); + retval = ovl (status, ""); } return retval; diff -r 5565b3e6eb60 -r 39b6d6ca3831 libinterp/dldfcn/__init_fltk__.cc --- a/libinterp/dldfcn/__init_fltk__.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libinterp/dldfcn/__init_fltk__.cc Sat Mar 23 12:19:59 2024 -0400 @@ -603,9 +603,21 @@ { std::string valstr = fltk_label.substr (idx1 + 1, len - 1); fltk_label.erase (idx1, len + 1); - val = atoi (valstr.c_str ()); - if (val > 0 && val < 99) - val++; + + // FIXME: Should we warn or error on invalid or out + // of range values in VALSTR? When atoi was used + // for conversion instead of std::stoi we did not. + // Was that intentional? + + try + { + val = std::stoi (valstr); + + if (val > 0 && val < 99) + val++; + } + catch (const std::invalid_argument&) { } + catch (const std::out_of_range&) { } } std::ostringstream valstream; valstream << val; diff -r 5565b3e6eb60 -r 39b6d6ca3831 libinterp/parse-tree/bp-table.cc --- a/libinterp/parse-tree/bp-table.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/libinterp/parse-tree/bp-table.cc Sat Mar 23 12:19:59 2024 -0400 @@ -370,6 +370,9 @@ // allow "in" and "at" to be implicit if (args(pos).is_string ()) { + // Default value. + tok = dbstop_in; + std::string arg = args(pos).string_value (); if (arg == "in") { @@ -386,10 +389,16 @@ tok = dbstop_if; pos++; } - else if (atoi (args(pos).string_value ().c_str ()) > 0) - tok = dbstop_at; else - tok = dbstop_in; + { + try + { + if (std::stoi (args(pos).string_value ()) > 0) + tok = dbstop_at; + } + catch (const std::invalid_argument&) { } + catch (const std::out_of_range&) { } + } } else tok = dbstop_at; @@ -431,8 +440,27 @@ // FIXME: we really want to distinguish number // vs. method name here. - if (atoi (arg.c_str ()) == 0) + // FIXME: I'm not sure what the + + bool int_conv_ok = true; + + try + { + if (std::stoi (arg) == 0) + int_conv_ok = false; + } + catch (const std::invalid_argument&) { + int_conv_ok = false; + } + catch (const std::out_of_range&) + { + int_conv_ok = false; + } + + if (! int_conv_ok) + { + // Assume we are looking at a function name. // We have class and function names but already // stored the class name in fcn_name. class_name = fcn_name; @@ -458,12 +486,27 @@ { if (args(pos).is_string ()) { - int line = atoi (args(pos).string_value ().c_str ()); + bool skip = false; + + std::string str = args(pos).string_value (); + + try + { + int line = std::stoi (str); - if (line > 0) - lines.insert (line); - else - break; // may be "if" or a method name + if (line > 0) + lines.insert (line); + else + break; // may be "if" or a method name + } + catch (const std::invalid_argument&) + { + break; // may be "if" or a method name + } + catch (const std::out_of_range&) + { + error ("dbstop: location value out of range '%s'", str.c_str ()); + } } else if (args(pos).isnumeric ()) { diff -r 5565b3e6eb60 -r 39b6d6ca3831 liboctave/util/data-conv.cc --- a/liboctave/util/data-conv.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/liboctave/util/data-conv.cc Sat Mar 23 12:19:59 2024 -0400 @@ -391,8 +391,21 @@ { if (s[pos] == '*') { - block_size = atoi (s.c_str ()); - s = s.substr (pos+1); + try + { + block_size = std::stoi (s); + s = s.substr (pos+1); + } + catch (const std::invalid_argument&) + { + (*current_liboctave_error_handler) + ("invalid repeat count in '%s'", s.c_str ()); + } + catch (const std::out_of_range&) + { + (*current_liboctave_error_handler) + ("repeat count out of range in '%s'", s.c_str ()); + } } else (*current_liboctave_error_handler) @@ -458,8 +471,21 @@ { if (s[pos] == '*') { - block_size = atoi (s.c_str ()); - s = s.substr (pos+1); + try + { + block_size = std::stoi (s); + s = s.substr (pos+1); + } + catch (const std::invalid_argument&) + { + (*current_liboctave_error_handler) + ("invalid repeat count in '%s'", s.c_str ()); + } + catch (const std::out_of_range&) + { + (*current_liboctave_error_handler) + ("repeat count out of range in '%s'", s.c_str ()); + } } else (*current_liboctave_error_handler) diff -r 5565b3e6eb60 -r 39b6d6ca3831 liboctave/util/pathsearch.cc --- a/liboctave/util/pathsearch.cc Fri Mar 22 19:45:02 2024 +0100 +++ b/liboctave/util/pathsearch.cc Sat Mar 23 12:19:59 2024 -0400 @@ -108,10 +108,35 @@ if (! octave_kpse_initialized) { - std::string val = sys::env::getenv ("KPATHSEA_DEBUG"); + std::string env_val = sys::env::getenv ("KPATHSEA_DEBUG"); + + if (! env_val.empty ()) + { + unsigned int env_debug_flags = 0; + + try + { + unsigned long val = std::stoul (env_val); - if (! val.empty ()) - kpse_debug |= atoi (val.c_str ()); + if (val > std::numeric_limits::max ()) + (*current_liboctave_warning_with_id_handler) + ("Octave:kpathsea-debug-value-ignored", "directory_path::init: ignoring out of range KPATHSEA_DEBUG value '%s'", env_val.c_str ()); + else + env_debug_flags = val; + } + catch (const std::invalid_argument&) + { + (*current_liboctave_warning_with_id_handler) + ("Octave:kpathsea-debug-value-ignored", "directory_path::init: ignoring invalid KPATHSEA_DEBUG value '%s'", env_val.c_str ()); + } + catch (const std::out_of_range&) + { + (*current_liboctave_warning_with_id_handler) + ("Octave:kpathsea-debug-value-ignored", "directory_path::init: ignoring out of range KPATHSEA_DEBUG value '%s'", env_val.c_str ()); + } + + kpse_debug |= env_debug_flags; + } octave_kpse_initialized = true; }