summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/options.c12
-rw-r--r--bin/sh/tests/builtins/getopts6.07
-rw-r--r--bin/sh/tests/builtins/getopts7.06
3 files changed, 17 insertions, 8 deletions
diff --git a/bin/sh/options.c b/bin/sh/options.c
index caaa884..8594c57 100644
--- a/bin/sh/options.c
+++ b/bin/sh/options.c
@@ -480,7 +480,7 @@ atend:
INTON;
}
c = '?';
- goto bad;
+ goto out;
}
if (*++q == ':')
q++;
@@ -501,7 +501,7 @@ atend:
INTON;
c = '?';
}
- goto bad;
+ goto out;
}
if (p == **optnext)
@@ -511,14 +511,10 @@ atend:
}
else
setvarsafe("OPTARG", "", 0);
- ind = *optnext - optfirst + 1;
- goto out;
-bad:
- ind = 1;
- *optnext = NULL;
- p = NULL;
out:
+ if (*optnext != NULL)
+ ind = *optnext - optfirst + 1;
*optptr = p;
fmtstr(s, sizeof(s), "%d", ind);
err |= setvarsafe("OPTIND", s, VNOFUNC);
diff --git a/bin/sh/tests/builtins/getopts6.0 b/bin/sh/tests/builtins/getopts6.0
new file mode 100644
index 0000000..1d3c39b
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts6.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+set -- -x -y
+getopts :x var || echo "First getopts bad: $?"
+getopts :x var
+r=$?
+[ r != 0 ] && [ "$OPTIND" = 3 ]
diff --git a/bin/sh/tests/builtins/getopts7.0 b/bin/sh/tests/builtins/getopts7.0
new file mode 100644
index 0000000..3745555
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts7.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+set -- -x
+getopts :x: var
+r=$?
+[ r != 0 ] && [ "$OPTIND" = 2 ]
OpenPOWER on IntegriCloud