From 5640acb50da707b404e00e9a20ba3fb3ec334a91 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 3 May 2015 12:41:05 -0500 Subject: If a shortopt is configured out right before a bare longopt, the option parsing infrastructure segfaults because there's no next shortopt but the list isn't empty. (There was a test for this, but we're simultaneously traversing two lists and it was testing the wrong one.) --- scripts/mkflags.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/mkflags.c b/scripts/mkflags.c index 228cd2f8..d87087bc 100644 --- a/scripts/mkflags.c +++ b/scripts/mkflags.c @@ -122,10 +122,14 @@ int main(int argc, char *argv[]) char *gaps, *mgaps, c; unsigned bit; - *command = 0; + *command = *flags = *allflags = 0; bit = fscanf(stdin, "%255s \"%1023[^\"]\" \"%1023[^\"]\"\n", command, flags, allflags); + if (getenv("DEBUG")) + fprintf(stderr, "command=%s, flags=%s, allflags=%s\n", + command, flags, allflags); + if (!*command) break; if (bit != 3) { fprintf(stderr, "\nError in %s (duplicate command?)\n", command); @@ -182,8 +186,7 @@ int main(int argc, char *argv[]) if (flist) flist = flist->next; } } else if (aflist->command) { - if (flist && (!aflist->command || *aflist->command == *flist->command)) - { + if (flist && (!flist->command || *aflist->command == *flist->command)) { if (aflist->command) sprintf(out, "#define FLAG_%c (1<<%d)\n", *aflist->command, bit); flist = flist->next; -- cgit v1.2.3