From 4f4e1384b4299611924a39f59f536b4964806135 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 17 Apr 2013 20:14:59 +0200 Subject: [PATCH] Do not segfault on unknown options. --- main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 55548ba..e953a8c 100644 --- a/main.cpp +++ b/main.cpp @@ -248,9 +248,10 @@ int main(int argc, char **argv) static const option long_options[] = { { "state", required_argument, 0, 's' }, { "test-config", no_argument, 0, 't' }, + { 0, 0, 0, 0 } }; int option_index = 0; - int c = getopt_long (argc, argv, "s:t", long_options, &option_index); + int c = getopt_long(argc, argv, "s:t", long_options, &option_index); if (c == -1) { break; @@ -263,7 +264,8 @@ int main(int argc, char **argv) test_config = true; break; default: - assert(false); + fprintf(stderr, "Unknown option '%s'\n", argv[option_index]); + exit(1); } } -- 2.39.2