From fed2ce5668c448f7b2711f57c551e1eeb8af2a7d Mon Sep 17 00:00:00 2001 From: Victor Geraldsson Date: Wed, 23 Dec 2020 23:54:46 +0100 Subject: [PATCH] Fix some options not taking effect Fixes GH-20 --- src/options.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/options.c b/src/options.c index 790e4bc..41cdb59 100644 --- a/src/options.c +++ b/src/options.c @@ -5,9 +5,22 @@ struct sect sect_hd = {""}; +static int to_integer(const char *str, int n) +{ + int i = *str=='-'; + if (str[i]>'0' && str[i]<='9') { + i++; + for (; ip = str; return 2; } - i = *str=='-'; - if (str[i]>'0' && str[i]<='9') { - val->integ = atoi(str); - i++; - for (; iinteg = to_integer(str, n)) != 0) { return 0; } -str: strncpy(val->str, str, 4); + strncpy(val->str, str, 4); if (n && n<4) val->str[n] = '\0'; return 1; @@ -129,7 +136,9 @@ int getopt_int(const char *sect_name, const char *key) if (o) { const char *s = opt_longstr(o); if (s) { - return atoi(s); + int d = to_integer(s, strlen(s)); + if (d != 0) + return d; } return o->val.integ; }