summaryrefslogtreecommitdiffstats
path: root/cmd-list-keys.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-11-05 12:04:50 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-11-05 12:04:50 +0000
commit05855393f0e9c7c9228da3d6388c6d02a3083ef4 (patch)
treefddfb6062d53d736b9f9623f7b306cfdbc8f2dfe /cmd-list-keys.c
parenta790e16fa25e0fce4fc0f8ac6e83147a83ede3e8 (diff)
key_string_lookup_key uses a static buffer, so copy its output into the working
buffer before calling the command print function which can also use it (eg send-keys).
Diffstat (limited to 'cmd-list-keys.c')
-rw-r--r--cmd-list-keys.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/cmd-list-keys.c b/cmd-list-keys.c
index db64e244..f4bd064a 100644
--- a/cmd-list-keys.c
+++ b/cmd-list-keys.c
@@ -47,7 +47,8 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
struct cmd_target_data *data = self->data;
struct key_binding *bd;
const char *key;
- char tmp[BUFSIZ], keytmp[64];
+ char tmp[BUFSIZ];
+ size_t used;
int width, keywidth;
if (data->target != NULL)
@@ -70,14 +71,15 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
key = key_string_lookup_key(bd->key & ~KEYC_PREFIX);
if (key == NULL)
continue;
+ if (!(bd->key & KEYC_PREFIX))
+ used = xsnprintf(tmp, sizeof tmp, "[%s]: ", key);
+ else
+ used = xsnprintf(tmp, sizeof tmp, "%*s: ", width, key);
+ if (used >= sizeof tmp)
+ continue;
- *tmp = '\0';
- cmd_list_print(bd->cmdlist, tmp, sizeof tmp);
- if (!(bd->key & KEYC_PREFIX)) {
- xsnprintf(keytmp, sizeof keytmp, "[%s]", key);
- key = keytmp;
- }
- ctx->print(ctx, "%*s: %s", width, key, tmp);
+ cmd_list_print(bd->cmdlist, tmp + used, (sizeof tmp) - used);
+ ctx->print(ctx, "%s", tmp);
}
return (0);