Mercurial > octave
comparison libinterp/dldfcn/__init_fltk__.cc @ 33240:4e5bc9c4f657
use std::stoi or std::stoul instead of atoi (bug #65342)
The std::stoi and std::stoul functions allow us to distinguish between
invalid values and out of range values instead of just returning 0 for
any conversion failure as atoi does. In the following changes, we now
attempt to provide better diagnostics where possible.
* pathsearch.cc (directory_path::init): Use std::stoul instead of
atoi. Issue warnings for out of range or invalid values.
* __init_fltk__.cc (fltk_uimenu::add_entry): Use std::stoi instead of atoi.
* event-manager.cc (F__event_manager_file_dialog__): Use std::stoi
instead of atoi.
* bp-table.cc (bp_table::parse_dbfunction_params): Use std::stoi
instead of atoi.
* data-conv.cc (oct_data_conv::string_to_data_type): Use std::stoi
instead of atoi.
* debug.cc (parse_start_end, parse_integer_argument): New static functions.
(Fdbtype): Use parse_start_end to improve parsing of integer arguments.
(Fdblist, Fdbstack, do_dbupdown): Use parse_integer_argument to
improve handling of integer argument values.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 23 Mar 2024 12:13:17 -0400 |
parents | 2e484f9f1f18 |
children | 79cfa1b7a813 |
comparison
equal
deleted
inserted
replaced
33239:775dde0cb3e5 | 33240:4e5bc9c4f657 |
---|---|
601 int val = 1; | 601 int val = 1; |
602 if (len > 0) | 602 if (len > 0) |
603 { | 603 { |
604 std::string valstr = fltk_label.substr (idx1 + 1, len - 1); | 604 std::string valstr = fltk_label.substr (idx1 + 1, len - 1); |
605 fltk_label.erase (idx1, len + 1); | 605 fltk_label.erase (idx1, len + 1); |
606 val = atoi (valstr.c_str ()); | 606 |
607 if (val > 0 && val < 99) | 607 // FIXME: Should we warn or error on invalid or out |
608 val++; | 608 // of range values in VALSTR? When atoi was used |
609 // for conversion instead of std::stoi we did not. | |
610 // Was that intentional? | |
611 | |
612 try | |
613 { | |
614 val = std::stoi (valstr); | |
615 | |
616 if (val > 0 && val < 99) | |
617 val++; | |
618 } | |
619 catch (const std::invalid_argument&) { } | |
620 catch (const std::out_of_range&) { } | |
609 } | 621 } |
610 std::ostringstream valstream; | 622 std::ostringstream valstream; |
611 valstream << val; | 623 valstream << val; |
612 fltk_label += '(' + valstream.str () + ')'; | 624 fltk_label += '(' + valstream.str () + ')'; |
613 } | 625 } |