diff options
author | Subhaditya Nath <sn03.general@gmail.com> | 2023-02-06 20:38:47 +0530 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2024-04-06 15:34:33 +0800 |
commit | 96b972aa3d15317cc1e853543a918b2b727e4566 (patch) | |
tree | 42df89947434203e5bb667c904a5f9891d9443d4 | |
parent | 933e016f29ffd4863b9b2857d240716f7b2728b5 (diff) | |
download | dash-96b972aa3d15317cc1e853543a918b2b727e4566.tar.gz |
options: Fix getopts handling of colon in optstr
Putting a colon at the beginning of optstring to silence errors doesn't
mean that the colon is a valid option. Before this patch, dash treated
-: as a valid option if the optstring started with a colon. This patch
fixes that problem.
Test:
getopts :a opt -:
echo $opt$OPTARG
Correct output - ?:
Invalid output - :
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | src/options.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/options.c b/src/options.c index e192191..8101cf5 100644 --- a/src/options.c +++ b/src/options.c @@ -467,7 +467,7 @@ atend: } c = *p++; - for (q = optstr; *q != c; ) { + for (q = optstr[0] == ':' ? optstr + 1 : optstr; *q != c; ) { if (*q == '\0') { if (optstr[0] == ':') { s[0] = c; |