From 7473c59d050ceaaecd093c04af8fb7acddc7aa5b Mon Sep 17 00:00:00 2001 From: Philipp Joram Date: Wed, 25 Nov 2015 20:33:16 +0100 Subject: [PATCH] Fix segfault when launching with unkown option Bug: When launching with an unkown option, ttysolitaire crashes with a segfault. Reason: This is due to getopt_long() not knowing where to terminate the search for matching options in options[]. Fix: Append an additional Element to options[] containing only zeroes. This is in compliance with the GNU docs. See `man getopt_long` for reference. --- src/ttysolitaire.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ttysolitaire.c b/src/ttysolitaire.c index d6285ed..1861f3f 100644 --- a/src/ttysolitaire.c +++ b/src/ttysolitaire.c @@ -22,7 +22,8 @@ int main(int argc, char *argv[]) { static const struct option options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, - {"passes", required_argument, NULL, 'p'} + {"passes", required_argument, NULL, 'p'}, + {0, 0, 0, 0} }; program_name = argv[0];