From fd90061c24d2a36452b8fe6aeb636faab6b2bb8f Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 31 Aug 2016 13:23:44 +0200 Subject: [PATCH 1/3] Make argument parsing errors fatal When you run "awesome --foobar", a warning will be printed (by getopt_long()) and awesome just ignores the invalid argument. That's unusual and weird. This commit produces an error instead. Signed-off-by: Uli Schlachter --- awesome.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/awesome.c b/awesome.c index ef5d18f6..8e8d5dde 100644 --- a/awesome.c +++ b/awesome.c @@ -524,6 +524,9 @@ main(int argc, char **argv) case 'r': replace_wm = true; break; + default: + exit_help(EXIT_FAILURE); + break; } /* Get XDG basedir data */ From 4cbf87b441bf36961827a7372fcf8172bc03a75a Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 31 Aug 2016 13:27:07 +0200 Subject: [PATCH 2/3] Remove empty-argument checks This code removes code which could only be hit be running awesome --search '' or awesome -c ''. In both cases there are many possibilities for weird/invalid arguments and I don't see why the empty string deserves special treatment. Note that awesome --search does NOT hit this code, because getopt_long handles the case of "completely missing" arguments itself. Signed-off-by: Uli Schlachter --- awesome.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/awesome.c b/awesome.c index 8e8d5dde..0f715967 100644 --- a/awesome.c +++ b/awesome.c @@ -507,16 +507,10 @@ main(int argc, char **argv) run_test = true; break; case 'c': - if(a_strlen(optarg)) - confpath = a_strdup(optarg); - else - fatal("-c option requires a file name"); + confpath = a_strdup(optarg); break; case 's': - if(a_strlen(optarg)) - string_array_append(&searchpath, a_strdup(optarg)); - else - fatal("-s option requires a directory name"); + string_array_append(&searchpath, a_strdup(optarg)); break; case 'a': no_argb = true; From e1d5c0c925597cfa6c427b1a5176a80e03ec8c29 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 31 Aug 2016 13:31:16 +0200 Subject: [PATCH 3/3] Do not allow multiple --config arguments Otherwise there is a small, unimportant memory leak. More important is the fact that later such flags overwrite earlier flags. Signed-off-by: Uli Schlachter --- awesome.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/awesome.c b/awesome.c index 0f715967..16f5eed3 100644 --- a/awesome.c +++ b/awesome.c @@ -507,6 +507,8 @@ main(int argc, char **argv) run_test = true; break; case 'c': + if (confpath != NULL) + fatal("--config may only be specified once"); confpath = a_strdup(optarg); break; case 's':