Mercurial > octave
changeset 22090:66db9a493c84
avoid accessing optarg and optind directly (bug #48454)
* getopt-wrapper.h, getopt-wrapper.c (octave_optarg_wrapper,
octave_optind_wrapper): New functions.
* octave.cc (cmdline_args::cmdline_args): Use them instead of optarg
and optind.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 11 Jul 2016 16:34:02 -0400 |
parents | c2c668b3051b |
children | 0f6fc2ec3b1a |
files | libinterp/octave.cc liboctave/wrappers/getopt-wrapper.c liboctave/wrappers/getopt-wrapper.h |
diffstat | 3 files changed, 37 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave.cc Sun Jul 10 07:15:21 2016 -0400 +++ b/libinterp/octave.cc Mon Jul 11 16:34:02 2016 -0400 @@ -430,8 +430,8 @@ break; case 'p': - if (optarg) - m_command_line_path.push_back (optarg); + if (octave_optarg_wrapper ()) + m_command_line_path.push_back (octave_optarg_wrapper ()); break; case 'q': @@ -450,28 +450,28 @@ break; case BUILT_IN_DOCSTRINGS_FILE_OPTION: - if (optarg) - Fbuilt_in_docstrings_file (octave_value (optarg)); + if (octave_optarg_wrapper ()) + Fbuilt_in_docstrings_file (octave_value (octave_optarg_wrapper ())); break; case DOC_CACHE_FILE_OPTION: - if (optarg) - Fdoc_cache_file (octave_value (optarg)); + if (octave_optarg_wrapper ()) + Fdoc_cache_file (octave_value (octave_optarg_wrapper ())); break; case EVAL_OPTION: - if (optarg) + if (octave_optarg_wrapper ()) { if (m_code_to_eval.empty ()) - m_code_to_eval = optarg; + m_code_to_eval = octave_optarg_wrapper (); else - m_code_to_eval += std::string (" ") + optarg; + m_code_to_eval += std::string (" ") + octave_optarg_wrapper (); } break; case EXEC_PATH_OPTION: - if (optarg) - m_exec_path = optarg; + if (octave_optarg_wrapper ()) + m_exec_path = octave_optarg_wrapper (); break; case FORCE_GUI_OPTION: @@ -479,18 +479,18 @@ break; case IMAGE_PATH_OPTION: - if (optarg) - m_image_path = optarg; + if (octave_optarg_wrapper ()) + m_image_path = octave_optarg_wrapper (); break; case INFO_FILE_OPTION: - if (optarg) - Finfo_file (octave_value (optarg)); + if (octave_optarg_wrapper ()) + Finfo_file (octave_value (octave_optarg_wrapper ())); break; case INFO_PROG_OPTION: - if (optarg) - Finfo_program (octave_value (optarg)); + if (octave_optarg_wrapper ()) + Finfo_program (octave_value (octave_optarg_wrapper ())); break; case DEBUG_JIT_OPTION: @@ -530,8 +530,8 @@ break; case TEXI_MACROS_FILE_OPTION: - if (optarg) - Ftexi_macros_file (octave_value (optarg)); + if (octave_optarg_wrapper ()) + Ftexi_macros_file (octave_value (octave_optarg_wrapper ())); break; case TRADITIONAL_OPTION: @@ -557,7 +557,8 @@ octave_print_terse_usage_and_exit (); } - m_remaining_args = string_vector (argv+optind, argc-optind); + m_remaining_args = string_vector (argv+octave_optind_wrapper (), + argc-octave_optind_wrapper ()); } cmdline_options::cmdline_options (const cmdline_options& opts)
--- a/liboctave/wrappers/getopt-wrapper.c Sun Jul 10 07:15:21 2016 -0400 +++ b/liboctave/wrappers/getopt-wrapper.c Mon Jul 11 16:34:02 2016 -0400 @@ -101,3 +101,15 @@ return retval; } + +char * +octave_optarg_wrapper (void) +{ + return optarg; +} + +int +octave_optind_wrapper (void) +{ + return optind; +}
--- a/liboctave/wrappers/getopt-wrapper.h Sun Jul 10 07:15:21 2016 -0400 +++ b/liboctave/wrappers/getopt-wrapper.h Mon Jul 11 16:34:02 2016 -0400 @@ -45,6 +45,10 @@ const struct octave_getopt_options *longopts, int *longind); +extern char *octave_optarg_wrapper (void); + +extern int octave_optind_wrapper (void); + #if defined __cplusplus } #endif