aboutsummaryrefslogtreecommitdiff
path: root/options.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2019-10-15 10:01:28 +0100
committerThomas Adam <thomas@xteddy.org>2019-10-15 10:01:28 +0100
commitfb7ce5b5d509db244111e130224f366ced28b228 (patch)
tree7359b965c7b1bd25e19256dba1c3318dca6359c4 /options.c
parenteb57cbcc296b10d8d9ea41930ab402717c800f9c (diff)
parent9fd62efcf0392cda0ddd1b7836e98da08d0a6f9f (diff)
downloadrtmux-fb7ce5b5d509db244111e130224f366ced28b228.tar.gz
rtmux-fb7ce5b5d509db244111e130224f366ced28b228.tar.bz2
rtmux-fb7ce5b5d509db244111e130224f366ced28b228.zip
Merge branch 'obsd-master'
Diffstat (limited to 'options.c')
-rw-r--r--options.c53
1 files changed, 35 insertions, 18 deletions
diff --git a/options.c b/options.c
index f683c566..6bc54ef8 100644
--- a/options.c
+++ b/options.c
@@ -321,6 +321,17 @@ options_array_item(struct options_entry *o, u_int idx)
return (RB_FIND(options_array, &o->value.array, &a));
}
+static struct options_array_item *
+options_array_new(struct options_entry *o, u_int idx)
+{
+ struct options_array_item *a;
+
+ a = xcalloc(1, sizeof *a);
+ a->index = idx;
+ RB_INSERT(options_array, &o->value.array, a);
+ return (a);
+}
+
static void
options_array_free(struct options_entry *o, struct options_array_item *a)
{
@@ -368,7 +379,14 @@ options_array_set(struct options_entry *o, u_int idx, const char *value,
return (-1);
}
- if (OPTIONS_IS_COMMAND(o) && value != NULL) {
+ if (value == NULL) {
+ a = options_array_item(o, idx);
+ if (a != NULL)
+ options_array_free(o, a);
+ return (0);
+ }
+
+ if (OPTIONS_IS_COMMAND(o)) {
pr = cmd_parse_from_string(value, NULL);
switch (pr->status) {
case CMD_PARSE_EMPTY:
@@ -384,34 +402,33 @@ options_array_set(struct options_entry *o, u_int idx, const char *value,
case CMD_PARSE_SUCCESS:
break;
}
- }
- a = options_array_item(o, idx);
- if (value == NULL) {
- if (a != NULL)
- options_array_free(o, a);
+ a = options_array_item(o, idx);
+ if (a == NULL)
+ a = options_array_new(o, idx);
+ else
+ options_value_free(o, &a->value);
+ a->value.cmdlist = pr->cmdlist;
return (0);
}
if (OPTIONS_IS_STRING(o)) {
+ a = options_array_item(o, idx);
if (a != NULL && append)
xasprintf(&new, "%s%s", a->value.string, value);
else
new = xstrdup(value);
+ if (a == NULL)
+ a = options_array_new(o, idx);
+ else
+ options_value_free(o, &a->value);
+ a->value.string = new;
+ return (0);
}
- if (a == NULL) {
- a = xcalloc(1, sizeof *a);
- a->index = idx;
- RB_INSERT(options_array, &o->value.array, a);
- } else
- options_value_free(o, &a->value);
-
- if (OPTIONS_IS_STRING(o))
- a->value.string = new;
- else if (OPTIONS_IS_COMMAND(o))
- a->value.cmdlist = pr->cmdlist;
- return (0);
+ if (cause != NULL)
+ *cause = xstrdup("wrong array type");
+ return (-1);
}
int