summary refs log tree commit diff
path: root/src/options.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-10-06 18:59:31 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2007-10-06 18:59:31 +0800
commit82a74acd4885849e1e5684002d78e55deb6a6843 (patch)
tree6c1f33a1ad6795b4d7bfa94c8fe07e9e287bc8fa /src/options.c
parent[MEMALLOC] Add pushstackmark (diff)
downloaddash-82a74acd4885849e1e5684002d78e55deb6a6843.tar.gz
dash-82a74acd4885849e1e5684002d78e55deb6a6843.zip
[BUILTIN] Treat OPTIND=0 in the same way as OPTIND=1
Previously setting OPTIND to 0 would cause subsequent getopts calls to fail.
This patch makes dash reset the getopts parameters the same way as OPTIND=1.

Both behaviours are allowed by POSIX but other common shells do tolerate this
case.
Diffstat (limited to 'src/options.c')
-rw-r--r--src/options.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/options.c b/src/options.c
index 85f1406..045345a 100644
--- a/src/options.c
+++ b/src/options.c
@@ -377,7 +377,7 @@ void
 getoptsreset(value)
 	const char *value;
 {
-	shellparam.optind = number(value);
+	shellparam.optind = number(value) ?: 1;
 	shellparam.optoff = -1;
 }
 
@@ -424,8 +424,6 @@ getopts(char *optstr, char *optvar, char **optfirst, int *optind, int *optoff)
 	char s[12];
 	char **optnext;
 
-	if (*optind < 1)
-		return 1;
 	optnext = optfirst + *optind - 1;
 
 	if (*optind <= 1 || *optoff < 0 || strlen(optnext[-1]) < *optoff)
f='/catgirl/commit/ui.c?h=enroll&id=b855ec62100efb8fa80ff68150f0789af180482a&follow=1'>Cast set but unused variables to voidJune McEnroe 2020-02-11Declare strlcatJune McEnroe 2020-02-11Check if VDSUSP existsJune McEnroe 2020-02-11Fix completeReplace iterationJune McEnroe 2020-02-11Use pkg(8) to configure on FreeBSDJune McEnroe 2020-02-11Remove legacy codeJune McEnroe 2020-02-11Add INSTALLING section to READMEJune McEnroe