From 0c06409c9d75d6f4560778113db834ae6e03591c Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 17 Mar 2020 16:02:38 +0000 Subject: [PATCH] getopt is not required to set optarg to NULL when there is no argument and some do not, so set it explicitly each time. --- arguments.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arguments.c b/arguments.c index 026272af..e2d18980 100644 --- a/arguments.c +++ b/arguments.c @@ -74,6 +74,7 @@ args_parse(const char *template, int argc, char **argv) optreset = 1; optind = 1; + optarg = NULL; while ((opt = getopt(argc, argv, template)) != -1) { if (opt < 0) @@ -83,6 +84,7 @@ args_parse(const char *template, int argc, char **argv) return (NULL); } args_set(args, opt, optarg); + optarg = NULL; } argc -= optind; argv += optind;