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.
This commit is contained in:
Rob Landley 2017-01-04 01:14:07 -06:00
parent eff6274390
commit 4d4ca28aca

View File

@ -159,11 +159,11 @@ static int gotflag(struct getoptflagstate *gof, struct opts *opt)
struct opts *bad; struct opts *bad;
unsigned i = 1; 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 (opt == bad || !(i & toys.optflags)) continue;
if (toys.optflags & bad->dex[2]) break; 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? // Does this option take an argument?