From: Steinar H. Gunderson Date: Wed, 17 Apr 2013 18:14:59 +0000 (+0200) Subject: Do not segfault on unknown options. X-Git-Tag: 1.0.0~82 X-Git-Url: https://git.sesse.net/?p=cubemap;a=commitdiff_plain;h=4f4e1384b4299611924a39f59f536b4964806135;ds=sidebyside Do not segfault on unknown options. --- 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); } }