commit d6026943d3aba8635662cd10905b7b559bbbca98
parent 55de8b5184f10a07bef8533b86804d3a95348f4b
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Sun, 28 Mar 2021 15:05:56 +0200
improve command-line parsing, fix crash with -fn without argument
Print the usage information instead of silently continuing.
On an invalid argument print the invalid argument and usage.
Diffstat:
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/svkbd.c b/svkbd.c
@@ -1151,12 +1151,11 @@ main(int argc, char *argv[])
die("svkbd-"VERSION);
} else if (!strcmp(argv[i], "-d")) {
isdock = True;
- continue;
} else if (!strncmp(argv[i], "-g", 2)) {
if (i >= argc - 1)
- continue;
+ usage(argv[0]);
- bitm = XParseGeometry(argv[i + 1], &xr, &yr, &wr, &hr);
+ bitm = XParseGeometry(argv[++i], &xr, &yr, &wr, &hr);
if (bitm & XValue)
wx = xr;
if (bitm & YValue)
@@ -1169,8 +1168,9 @@ main(int argc, char *argv[])
wx = -1;
if (bitm & YNegative && wy == 0)
wy = -1;
- i++;
} else if (!strcmp(argv[i], "-fn")) { /* font or font set */
+ if (i >= argc - 1)
+ usage(argv[0]);
fonts[0] = estrdup(argv[++i]);
} else if (!strcmp(argv[i], "-D")) {
debug = 1;
@@ -1186,19 +1186,20 @@ main(int argc, char *argv[])
pressonrelease = 0;
} else if (!strcmp(argv[i], "-l")) {
if (i >= argc - 1)
- continue;
+ usage(argv[0]);
free(layer_names_list);
layer_names_list = estrdup(argv[++i]);
} else if (!strcmp(argv[i], "-s")) {
if (i >= argc - 1)
- continue;
+ usage(argv[0]);
initial_layer_name = argv[++i];
} else if (!strcmp(argv[i], "-H")) {
if (i >= argc - 1)
- continue;
+ usage(argv[0]);
heightfactor = atoi(argv[++i]);
} else {
fprintf(stderr, "Invalid argument: %s\n", argv[i]);
+ usage(argv[0]);
exit(2);
}
}