summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2019-10-15 08:30:36 +0000
committernicm <nicm@openbsd.org>2019-10-15 08:30:36 +0000
commit76e38b2d7e39185ddde13225a1a8a19ecefd626a (patch)
tree15a0ec58d536e5521a52d8bcefa414b700a12cca
parentAdd support for percentage sizes for resize-pane ("-x 10%"). Also change (diff)
downloadwireguard-openbsd-76e38b2d7e39185ddde13225a1a8a19ecefd626a.tar.xz
wireguard-openbsd-76e38b2d7e39185ddde13225a1a8a19ecefd626a.zip
Rewrite options_array_set to be clearer and remove a spurious warning
with newer GCC. From Ben Boeckel.
-rw-r--r--usr.bin/tmux/options.c55
-rw-r--r--usr.bin/tmux/window-tree.c6
2 files changed, 39 insertions, 22 deletions
diff --git a/usr.bin/tmux/options.c b/usr.bin/tmux/options.c
index 56fee7da9c7..046dc5b21f2 100644
--- a/usr.bin/tmux/options.c
+++ b/usr.bin/tmux/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.53 2019/10/14 08:38:07 nicm Exp $ */
+/* $OpenBSD: options.c,v 1.54 2019/10/15 08:30:36 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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
diff --git a/usr.bin/tmux/window-tree.c b/usr.bin/tmux/window-tree.c
index df74da6abcf..1f3f63732f8 100644
--- a/usr.bin/tmux/window-tree.c
+++ b/usr.bin/tmux/window-tree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-tree.c,v 1.41 2019/09/25 19:05:59 nicm Exp $ */
+/* $OpenBSD: window-tree.c,v 1.42 2019/10/15 08:30:36 nicm Exp $ */
/*
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -191,7 +191,7 @@ window_tree_cmp_session(const void *a0, const void *b0)
const struct session *const *b = b0;
const struct session *sa = *a;
const struct session *sb = *b;
- int result;
+ int result = 0;
switch (window_tree_sort->field) {
case WINDOW_TREE_BY_INDEX:
@@ -226,7 +226,7 @@ window_tree_cmp_window(const void *a0, const void *b0)
const struct winlink *wlb = *b;
struct window *wa = wla->window;
struct window *wb = wlb->window;
- int result;
+ int result = 0;
switch (window_tree_sort->field) {
case WINDOW_TREE_BY_INDEX: