summaryrefslogtreecommitdiff
path: root/src/options/options_template.cpp
diff options
context:
space:
mode:
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>2020-04-21 00:33:50 -0500
committerGitHub <noreply@github.com>2020-04-21 00:33:50 -0500
commit233dca9a28575631dec2cf004fe07fe6b994a9df (patch)
treee4dd3da6c9eb10eaecd02373edeba2a8d3cd2e70 /src/options/options_template.cpp
parentf6bd42406897e165f2c9faffd69ab8db0204004f (diff)
Fix for parse options related to binary name (#4368)
Possible fix for the nightlies. In some configurations, a unit test fails when using the function for parsing options via manual argv construction https://github.com/CVC4/CVC4/blob/master/test/unit/expr/expr_public.h#L58 This reverts a behavior change from 3dfb48b. In particular, we always parse and ignore the binary name instead of skipping it outright. This more accurately reflects the original code.
Diffstat (limited to 'src/options/options_template.cpp')
-rw-r--r--src/options/options_template.cpp18
1 files changed, 3 insertions, 15 deletions
diff --git a/src/options/options_template.cpp b/src/options/options_template.cpp
index faaa446ce..8a227a2e7 100644
--- a/src/options/options_template.cpp
+++ b/src/options/options_template.cpp
@@ -574,8 +574,9 @@ void Options::parseOptionsRecursive(Options* options,
optreset = 1; // on BSD getopt() (e.g. Mac OS), might need this
#endif /* HAVE_DECL_OPTRESET */
- // start with position after the binary name
- int main_optind = 1;
+ // We must parse the binary name, which is manually ignored below. Setting
+ // this to 1 leads to incorrect behavior on some platforms.
+ int main_optind = 0;
int old_optind;
@@ -618,19 +619,6 @@ void Options::parseOptionsRecursive(Options* options,
// The initial getopt_long call should always determine that argv[0]
// is not an option and returns -1. We always manually advance beyond
// this element.
- //
- // We have to reinitialize optind to 0 instead of 1 as we need to support
- // changing the argv array passed to getopt.
- // This is needed as are using GNU extensions.
- // From: http://man7.org/linux/man-pages/man3/getopt.3.html
- // A program that scans multiple argument vectors, or rescans the same
- // vector more than once, and wants to make use of GNU extensions such
- // as '+' and '-' at the start of optstring, or changes the value of
- // POSIXLY_CORRECT between scans, must reinitialize getopt() by
- // resetting optind to 0, rather than the traditional value of 1.
- // (Resetting to 0 forces the invocation of an internal initialization
- // routine that rechecks POSIXLY_CORRECT and checks for GNU extensions
- // in optstring.)
if ( old_optind == 0 && c == -1 ) {
Assert(main_optind > 0);
continue;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback