Inline comments below.
> --- tsort.c 29 Jul 2015 10:42:37 -0000 1.26
> +++ tsort.c 28 Aug 2015 08:03:59 -0000
> @@ -798,6 +799,43 @@ find_longest_cycle(struct array *h, stru
>
> #define plural(n) ((n) > 1 ? "s" : "")
>
> +static void
> +TAME(int flags, const char *wl[])
> +{
> + if (tame(flags, wl) != 0)
> + err(1, "untamed program");
> +}
> +
> +static void
> +compute_whitelist(int argc, char *argv[], char *args[])
> +{
> + int c;
> + int i = 0;
> +
> + while ((c = getopt(argc, argv, "h:flqrvw")) != -1) {
> + switch(c) {
> + case 'h':
> + args[i++] = optarg;
This assignment can write past the end of 'args' when the -h option is
given multiple times.
> + /*FALLTHRU*/
> + case 'f':
> + case 'l':
> + case 'q':
> + case 'r':
> + case 'v':
> + case 'w':
> + break;
> + default:
> + usage();
> + }
> + }
> + argc -= optind;
> + argv += optind;
> + if (argc == 1)
> + args[i++] = argv[0];
> + args[i] = NULL;
> + optind = optreset = 1;
> +}
> +
> int
> main(int argc, char *argv[])
> {
> @@ -806,6 +844,10 @@ main(int argc, char *argv[])
> warn_flag, hints_flag, verbose_flag;
> unsigned int order;
>
> + char *args[3];
How about something like this?
char **args = calloc(argc, sizeof(char *));
if (args == NULL)
err(1, "calloc");
In most cases this will probably be a waste of space, but at least it
keeps the code simple. The other option would be to fiddle with
realloc() in compute_whitelist().
> +
> + compute_whitelist(argc, argv, args);
> + TAME(TAME_STDIO|TAME_RPATH, args);
> order = 0;
>
> reverse_flag = quiet_flag = long_flag =
cheers,
natano