From ca22cbfab650ad9def1310f459d5003975a0912b Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 8 Nov 2019 18:16:42 -0500 Subject: Avoid calling getopt_long again after it returns -1 On GNU, calling getopt_long again will reset optind back to the first non-option argument, which would cause an infinite loop of reading the same configurtion file forever. --- config.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index a96cbb6..653ae16 100644 --- a/config.c +++ b/config.c @@ -42,7 +42,10 @@ int getopt_config( int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longindex ) { - int opt = getopt_long(argc, argv, optstring, longopts, longindex); + static int opt; + if (opt >= 0) { + opt = getopt_long(argc, argv, optstring, longopts, longindex); + } if (opt >= 0) return opt; for (;;) { -- cgit 1.4.1