Mercurial > octave
comparison 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 |
comparison
equal
deleted
inserted
replaced
33239:775dde0cb3e5 | 33240:4e5bc9c4f657 |
---|---|
106 { | 106 { |
107 static bool octave_kpse_initialized = false; | 107 static bool octave_kpse_initialized = false; |
108 | 108 |
109 if (! octave_kpse_initialized) | 109 if (! octave_kpse_initialized) |
110 { | 110 { |
111 std::string val = sys::env::getenv ("KPATHSEA_DEBUG"); | 111 std::string env_val = sys::env::getenv ("KPATHSEA_DEBUG"); |
112 | 112 |
113 if (! val.empty ()) | 113 if (! env_val.empty ()) |
114 kpse_debug |= atoi (val.c_str ()); | 114 { |
115 unsigned int env_debug_flags = 0; | |
116 | |
117 try | |
118 { | |
119 unsigned long val = std::stoul (env_val); | |
120 | |
121 if (val > std::numeric_limits<unsigned int>::max ()) | |
122 (*current_liboctave_warning_with_id_handler) | |
123 ("Octave:kpathsea-debug-value-ignored", "directory_path::init: ignoring out of range KPATHSEA_DEBUG value '%s'", env_val.c_str ()); | |
124 else | |
125 env_debug_flags = val; | |
126 } | |
127 catch (const std::invalid_argument&) | |
128 { | |
129 (*current_liboctave_warning_with_id_handler) | |
130 ("Octave:kpathsea-debug-value-ignored", "directory_path::init: ignoring invalid KPATHSEA_DEBUG value '%s'", env_val.c_str ()); | |
131 } | |
132 catch (const std::out_of_range&) | |
133 { | |
134 (*current_liboctave_warning_with_id_handler) | |
135 ("Octave:kpathsea-debug-value-ignored", "directory_path::init: ignoring out of range KPATHSEA_DEBUG value '%s'", env_val.c_str ()); | |
136 } | |
137 | |
138 kpse_debug |= env_debug_flags; | |
139 } | |
115 | 140 |
116 octave_kpse_initialized = true; | 141 octave_kpse_initialized = true; |
117 } | 142 } |
118 | 143 |
119 m_expanded_path = kpse_path_expand (m_orig_path); | 144 m_expanded_path = kpse_path_expand (m_orig_path); |