diff options
author | Hannes Eder <hannes@hanneseder.net> | 2009-01-08 21:50:56 +0100 |
---|---|---|
committer | Christopher Li <sparse@chrisli.org> | 2009-07-17 23:06:04 +0000 |
commit | 2b287c89f01e9e51afb6f219ee2b1934bfc4a082 (patch) | |
tree | e71830ecfbbdfa75ab749d5e15d653e88054e602 | |
parent | 507e53fbd95737f05615d1bd97803ce5457a4872 (diff) | |
download | sparse-2b287c89f01e9e51afb6f219ee2b1934bfc4a082.tar.gz |
refactor handle_switch_f
This also fixes a possible source of bugs in parsing other
-f<whatever> options, i.e. -ftabstop=foo would set the option -ffoo.
Signed-off-by: Hannes Eder <hannes@hanneseder.net>
-rw-r--r-- | lib.c | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -522,25 +522,34 @@ static char **handle_switch_O(char *arg, char **next) return next; } +static char **handle_switch_ftabstop(char *arg, char **next) +{ + char *end; + unsigned long val; + + if (*arg == '\0') + die("error: missing argument to \"-ftabstop=\""); + + /* we silently ignore silly values */ + val = strtoul(arg, &end, 10); + if (*end == '\0' && 1 <= val && val <= 100) + tabstop = val; + + return next; +} + static char **handle_switch_f(char *arg, char **next) { int flag = 1; arg++; - if (!strncmp(arg, "tabstop=", 8)) { - char *end; - unsigned long val; - arg += 8; + if (!strncmp(arg, "tabstop=", 8)) + return handle_switch_ftabstop(arg+8, next); - if (*arg == '\0') - die("error: missing argument to \"-ftabstop=\""); + /* handle switches w/ arguments above, boolean and only boolean below */ - /* we silently ignore silly values */ - val = strtoul(arg, &end, 10); - if (*end == '\0' && 1 <= val && val <= 100) - tabstop = val; - } else if (!strncmp(arg, "no-", 3)) { + if (!strncmp(arg, "no-", 3)) { flag = 0; arg += 3; } |