From de9870e7b9865bf3c81a3aaa9781f27ad62b67ef Mon Sep 17 00:00:00 2001 From: bel Date: Sat, 16 Aug 2014 01:12:22 +0200 Subject: [PATCH] Improve error handling in set_option --- src/main.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 4280d9d9..20be9002 100644 --- a/src/main.c +++ b/src/main.c @@ -273,17 +273,32 @@ static int set_option(char **options, const char *name, const char *value) /* unknown option */ return 0; case CONFIG_TYPE_NUMBER: + /* integer number > 0, e.g. number of threads */ if (atol(value)<1) { /* invalid number */ return 0; } break; + case CONFIG_TYPE_STRING: + /* any text */ + break; case CONFIG_TYPE_BOOLEAN: + /* boolean value, yes or no */ if ((0!=strcmp(value,"yes")) && (0!=strcmp(value,"no"))) { /* invalid boolean */ return 0; } break; + case CONFIG_TYPE_FILE: + case CONFIG_TYPE_DIRECTORY: + /* TODO: check this option when it is set, instead of calling verify_existence later */ + break; + case CONFIG_TYPE_EXT_PATTERN: + /* list of file extentions */ + break; + default: + die("Unknown option type - option %s", name); + break; } for (i = 0; i < MAX_OPTIONS; i++) { @@ -300,10 +315,14 @@ static int set_option(char **options, const char *name, const char *value) } if (i == MAX_OPTIONS) { - die("%s", "Too many options specified"); + die("Too many options specified"); } - /* TODO: check if this option is defined and the correct data type, return 1 (OK) or 0 (false) */ + if (options[2*i] == NULL || options[2*i + 1] == NULL) { + die("Out of memory"); + } + + /* option set correctly */ return 1; }