aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2017-01-04 01:14:07 -0600
committerRob Landley <rob@landley.net>2017-01-04 01:14:07 -0600
commit4d4ca28acaa44069893d06aea64e304809527b16 (patch)
treebcbe04386d7bbc4117e58488cca24eed9d172026
parenteff6274390d3facfa98787fc2d0d2fe99637a64f (diff)
downloadtoybox-4d4ca28acaa44069893d06aea64e304809527b16.tar.gz
An option can't exclude itself, so "abc[-ab][!abc]" with "command -a -b"
shouldn't segfault falling off the end of the list trying to report a nonexistent error condition.
-rw-r--r--lib/args.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/args.c b/lib/args.c
index e6378beb..00932de9 100644
--- a/lib/args.c
+++ b/lib/args.c
@@ -159,11 +159,11 @@ static int gotflag(struct getoptflagstate *gof, struct opts *opt)
struct opts *bad;
unsigned i = 1;
- for (bad=gof->opts, i=1; ;bad = bad->next, i<<=1) {
+ for (bad=gof->opts, i=1; bad ;bad = bad->next, i<<=1) {
if (opt == bad || !(i & toys.optflags)) continue;
if (toys.optflags & bad->dex[2]) break;
}
- help_exit("No '%c' with '%c'", opt->c, bad->c);
+ if (bad) help_exit("No '%c' with '%c'", opt->c, bad->c);
}
// Does this option take an argument?