Mercurial > octave
diff liboctave/util/pathsearch.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 |
line wrap: on
line diff
--- a/liboctave/util/pathsearch.cc Fri Mar 22 23:51:33 2024 -0400 +++ b/liboctave/util/pathsearch.cc Sat Mar 23 12:13:17 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<unsigned int>::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; }