summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-08-25 17:10:17 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-08-25 17:10:17 +0200
commit7e15e18817554d1a007d6857504224cdef37b939 (patch)
tree0ac3f5835bd89c9d4d6b29cbcc79bb846abb767f
parent74d577ab01d81bc6687841411d10b7367b474944 (diff)
afb-config: copy string values
Change-Id: Ibbc5924adef104d9ec7399e7943baa1d799d2572 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-config.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/afb-config.c b/src/afb-config.c
index 2fcf55a3..efa86f23 100644
--- a/src/afb-config.c
+++ b/src/afb-config.c
@@ -309,7 +309,7 @@ static const char *name_of_option(int optc)
return o->name ? : "<unknown-option-name>";
}
-static char *argvalstr(int optc)
+static const char *current_argument(int optc)
{
if (optarg == 0) {
ERROR("option [--%s] needs a value i.e. --%s=xxx",
@@ -319,11 +319,22 @@ static char *argvalstr(int optc)
return optarg;
}
+static char *argvalstr(int optc)
+{
+ char *result = strdup(current_argument(optc));
+ if (result == NULL) {
+ ERROR("can't alloc memory");
+ exit(1);
+ }
+ return result;
+}
+
static int argvalenum(int optc, struct enumdesc *desc)
{
int i;
size_t len;
- char *list, *name = argvalstr(optc);
+ char *list;
+ const char *name = current_argument(optc);
i = 0;
while(desc[i].name && strcmp(desc[i].name, name))
@@ -353,10 +364,10 @@ static int argvalenum(int optc, struct enumdesc *desc)
static int argvalint(int optc, int mini, int maxi, int base)
{
- char *beg, *end;
+ const char *beg, *end;
long int val;
- beg = argvalstr(optc);
- val = strtol(beg, &end, base);
+ beg = current_argument(optc);
+ val = strtol(beg, (char**)&end, base);
if (*end || end == beg) {
ERROR("option [--%s] requires a valid integer (found %s)",
name_of_option(optc), beg);