Discussion:
[PATCH 1/1] neww: Check indexes before window names
Thomas Adam
2014-12-01 23:57:43 UTC
Permalink
In the case of creating a new window, tmux would end up checking the window name
before the index. This is usually OK, save for the fact that if a window ever
has as its title, the same number as the index, then the check is in error.

Instead, make cmd_lookup_index() check the index and then the title; returning
early if the index matches.
---
cmd.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/cmd.c b/cmd.c
index eeffe4c..ae0e4b1 100644
--- a/cmd.c
+++ b/cmd.c
@@ -711,15 +711,15 @@ cmd_lookup_index(struct session *s, const char *name, int *ambiguous)
const char *errstr;
u_int idx;

+ idx = strtonum(name, 0, INT_MAX, &errstr);
+ if (errstr == NULL)
+ return (idx);
+
if ((wl = cmd_lookup_window(s, name, ambiguous)) != NULL)
return (wl->idx);
if (*ambiguous)
return (-1);

- idx = strtonum(name, 0, INT_MAX, &errstr);
- if (errstr == NULL)
- return (idx);
-
return (-1);
}
--
2.0.1
Thomas Adam
2014-12-02 00:01:58 UTC
Permalink
Post by Thomas Adam
In the case of creating a new window, tmux would end up checking the window name
before the index. This is usually OK, save for the fact that if a window ever
has as its title, the same number as the index, then the check is in error.
Instead, make cmd_lookup_index() check the index and then the title; returning
early if the index matches.
I appreciate this change is a difference in behaviour, but it actually
makes sense to me. Opinions?

-- Thomas Adam

Loading...