From c23a0d84b029676832ea0f2eeb0caa8c47d0500d Mon Sep 17 00:00:00 2001 From: dana Date: Mon, 3 May 2021 18:08:11 -0500 Subject: 48614: getopts: Calculate OPTIND according to POSIX_BUILTINS --- Src/builtin.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Src/builtin.c') diff --git a/Src/builtin.c b/Src/builtin.c index efa20607e..b7ceefd55 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5568,6 +5568,11 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun /* check for legality */ if(opch == ':' || !(p = memchr(optstr, opch, lenoptstr))) { p = "?"; + /* Keep OPTIND correct if the user doesn't return after the error */ + if (isset(POSIXBUILTINS)) { + optcind = 0; + zoptind++; + } zsfree(zoptarg); setsparam(var, ztrdup(p)); if(quiet) { @@ -5584,6 +5589,11 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun if(p[1] == ':') { if(optcind == lenstr) { if(!args[zoptind]) { + /* Fix OPTIND as above */ + if (isset(POSIXBUILTINS)) { + optcind = 0; + zoptind++; + } zsfree(zoptarg); if(quiet) { setsparam(var, ztrdup(":")); -- cgit 1.4.1