summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2020-03-17 16:02:38 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2020-03-18 07:54:37 +0000
commit0c06409c9d75d6f4560778113db834ae6e03591c (patch)
tree06c2cc304e45edd0fd6b6011cc893d3d045879a9
parent617136c234f1a39c06e0ec4eed5c3ebea02cc85d (diff)
getopt is not required to set optarg to NULL when there is no argument
and some do not, so set it explicitly each time.
-rw-r--r--arguments.c2
1 files changed, 2 insertions, 0 deletions
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;