Discussion:
patch to stop bad style from setting style to default
J Raynor
2015-02-17 06:01:34 UTC
Permalink
Right now, if you try to set a style with a bad value, tmux will
return an error, but it'll set the style to default. This happens
even if the style isn't currently set.

For example:

localhost> tmux show -w
localhost> tmux set pane-border-style bg=BadValue
bad style: bg=BadValue
localhost> tmux show -w
pane-border-style default


localhost> tmux set pane-border-style bg=red
localhost> tmux show -w
pane-border-style bg=red
localhost> tmux set pane-border-style bg=AnotherBadValue
bad style: bg=AnotherBadValue
localhost> tmux show -w
pane-border-style default


I've attached a patch that changes this behavior. If you pass a bad
value, then you still get the error message, but the option isn't set
or changed.
Nicholas Marriott
2015-02-18 15:33:21 UTC
Permalink
Good catch. Applied your diff and for completeness also changed
style_parse not to alter it's arguments on failure. Thanks
Post by J Raynor
Right now, if you try to set a style with a bad value, tmux will
return an error, but it'll set the style to default. This happens
even if the style isn't currently set.
localhost> tmux show -w
localhost> tmux set pane-border-style bg=BadValue
bad style: bg=BadValue
localhost> tmux show -w
pane-border-style default
localhost> tmux set pane-border-style bg=red
localhost> tmux show -w
pane-border-style bg=red
localhost> tmux set pane-border-style bg=AnotherBadValue
bad style: bg=AnotherBadValue
localhost> tmux show -w
pane-border-style default
I've attached a patch that changes this behavior. If you pass a bad
value, then you still get the error message, but the option isn't set
or changed.
diff --git a/options.c b/options.c
index 67f8abd..aa82d4a 100644
--- a/options.c
+++ b/options.c
@@ -167,20 +167,28 @@ options_set_style(struct options *oo, const char *name, const char *value,
int append)
{
struct options_entry *o;
+ struct grid_cell tmpgc;
- if ((o = options_find1(oo, name)) == NULL) {
+ o = options_find1(oo, name);
+
+ if (o == NULL || !append)
+ memcpy(&tmpgc, &grid_default_cell, sizeof tmpgc);
+ else
+ memcpy(&tmpgc, &o->style, sizeof tmpgc);
+
+
+ if (style_parse(&grid_default_cell, &tmpgc, value) == -1)
+ return (NULL);
+
+ if (o == NULL) {
o = xmalloc(sizeof *o);
o->name = xstrdup(name);
RB_INSERT(options_tree, &oo->tree, o);
} else if (o->type == OPTIONS_STRING)
free(o->str);
- if (!append)
- memcpy(&o->style, &grid_default_cell, sizeof o->style);
-
o->type = OPTIONS_STYLE;
- if (style_parse(&grid_default_cell, &o->style, value) == -1)
- return (NULL);
+ memcpy(&o->style, &tmpgc, sizeof tmpgc);
return (o);
}
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
https://lists.sourceforge.net/lists/listinfo/tmux-users
Loading...