diff --git a/src/wgetopt.h b/src/wgetopt.h index 45fe80f59..f5de1a57a 100644 --- a/src/wgetopt.h +++ b/src/wgetopt.h @@ -45,7 +45,7 @@ Cambridge, MA 02139, USA. */ class wgetopter_t { private: - bool initialized; + bool initialized = false; bool missing_arg_return_colon = false; void exchange(wchar_t **argv); @@ -65,9 +65,9 @@ class wgetopter_t { // For communication from `getopt' to the caller. When `getopt' finds an option that takes an // argument, the argument value is returned here. Also, when `ordering' is RETURN_IN_ORDER, each // non-option ARGV-element is returned here. - wchar_t *woptarg; + wchar_t *woptarg = nullptr; - const wchar_t *shortopts; + const wchar_t *shortopts = nullptr; // Index in ARGV of the next element to be scanned. This is used for communication to and from // the caller and for communication between successive calls to `getopt'. @@ -81,21 +81,21 @@ class wgetopter_t { // so far. // XXX 1003.2 says this must be 1 before any call. - int woptind; + int woptind = 0; // The next char to be scanned in the option-element in which the last option character we // returned was found. This allows us to pick up the scan where we left off. // // If this is zero, or a null string, it means resume the scan by advancing to the next // ARGV-element. - wchar_t *nextchar; + wchar_t *nextchar = nullptr; // Callers store zero here to inhibit the error message for unrecognized options. - int wopterr; + int wopterr = 0; // Set to an option character which was unrecognized. This must be initialized on some systems // to avoid linking in the system's own getopt implementation. - int woptopt; + int woptopt = '?'; // Describe how to deal with options that follow non-option ARGV-elements. // @@ -118,35 +118,19 @@ class wgetopter_t { // The special argument `--' forces an end of option-scanning regardless of the value of // `ordering'. In the case of RETURN_IN_ORDER, only `--' can cause `getopt' to return EOF with // `woptind' != ARGC. - enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering; + enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering = PERMUTE; // Handle permutation of arguments. // Describe the part of ARGV that contains non-options that have been skipped. `first_nonopt' // is the index in ARGV of the first of them; `last_nonopt' is the index after the last of them. - int first_nonopt; - int last_nonopt; + int first_nonopt = 0; + int last_nonopt = 0; + + wgetopter_t() {} - wgetopter_t() - : initialized(false), - missing_arg_return_colon(false), - woptarg(NULL), - shortopts(NULL), - woptind(0), - nextchar(NULL), - wopterr(0), - woptopt('?'), - ordering(), - first_nonopt(0), - last_nonopt(0) {} int wgetopt_long(int argc, wchar_t **argv, const wchar_t *options, const struct woption *long_options, int *opt_index); -#if 0 - // This function should never be used by fish. We keep the signature just in case we find a - // need to use it in the future. - int wgetopt_long_only(int argc, wchar_t **argv, const wchar_t *options, - const struct woption *long_options, int *opt_index); -#endif }; /// Describe the long-named options requested by the application. The LONG_OPTIONS argument to