summaryrefslogtreecommitdiffstats
path: root/cmd.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-10-14 20:52:28 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-10-14 20:52:28 +0000
commit1a3c334c753b9c22dc06105cc8009655bd9589c1 (patch)
tree7bf3fccb8124ecd285fc184aece98454e600c8ea /cmd.c
parentadad5574996cabc2e91bd267d2a86b3c6cec584d (diff)
cmd_find_client shouldn't die when there is an empty slot in the clients
array. DOH.
Diffstat (limited to 'cmd.c')
-rw-r--r--cmd.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/cmd.c b/cmd.c
index 198daa84..bf07c3b0 100644
--- a/cmd.c
+++ b/cmd.c
@@ -399,7 +399,7 @@ cmd_newest_client(void)
struct client *
cmd_find_client(struct cmd_ctx *ctx, const char *arg)
{
- struct client *c;
+ struct client *c, *lastc;
struct session *s;
char *tmparg;
size_t arglen;
@@ -415,16 +415,17 @@ cmd_find_client(struct cmd_ctx *ctx, const char *arg)
*/
s = cmd_current_session(ctx);
if (s != NULL) {
- c = NULL;
+ lastc = NULL;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- if (ARRAY_ITEM(&clients, i)->session == s) {
- if (c != NULL)
+ c = ARRAY_ITEM(&clients, i);
+ if (c != NULL && c->session == s) {
+ if (lastc != NULL)
break;
- c = ARRAY_ITEM(&clients, i);
+ lastc = c;
}
}
- if (i == ARRAY_LENGTH(&clients) && c != NULL)
- return (c);
+ if (i == ARRAY_LENGTH(&clients) && lastc != NULL)
+ return (lastc);
}
return (cmd_newest_client());
}