adding some minor error catching

This commit is contained in:
Maarten van Gompel 2020-08-02 15:46:17 +02:00 committed by Hiltjo Posthuma
parent 4dab556580
commit 12fe4c8923
1 changed files with 8 additions and 2 deletions

10
svkbd.c
View File

@ -886,6 +886,7 @@ main(int argc, char *argv[]) {
const char* layers_env = getenv("SVKBD_LAYERS"); const char* layers_env = getenv("SVKBD_LAYERS");
if (layers_env != NULL) { if (layers_env != NULL) {
layer_names_list = malloc(128); layer_names_list = malloc(128);
if (!layer_names_list) die("memory allocation error\n");
strcpy(layer_names_list, layers_env); strcpy(layer_names_list, layers_env);
} }
const char* heightfactor_s = getenv("SVKBD_HEIGHTFACTOR"); const char* heightfactor_s = getenv("SVKBD_HEIGHTFACTOR");
@ -929,7 +930,10 @@ main(int argc, char *argv[]) {
} else if(!strcmp(argv[i], "-l")) { } else if(!strcmp(argv[i], "-l")) {
if(i >= argc - 1) if(i >= argc - 1)
continue; continue;
if (layer_names_list == NULL) layer_names_list = malloc(128); if (layer_names_list == NULL) {
layer_names_list = malloc(128);
if (!layer_names_list) die("memory allocation error\n");
}
strcpy(layer_names_list, argv[++i]); strcpy(layer_names_list, argv[++i]);
} else if(!strcmp(argv[i], "-s")) { } else if(!strcmp(argv[i], "-s")) {
if(i >= argc - 1) if(i >= argc - 1)
@ -945,6 +949,8 @@ main(int argc, char *argv[]) {
} }
} }
if (heightfactor <= 0) die("height factor must be a positive integer\n");
init_layers(layer_names_list, initial_layer_name); init_layers(layer_names_list, initial_layer_name);
if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
@ -955,6 +961,6 @@ main(int argc, char *argv[]) {
run(); run();
cleanup(); cleanup();
XCloseDisplay(dpy); XCloseDisplay(dpy);
if (layer_names_list != NULL) free(layer_names_list); free(layer_names_list);
return 0; return 0;
} }