summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-copy-buffer.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2009-09-07 18:50:45 +0000
committernicm <nicm@openbsd.org>2009-09-07 18:50:45 +0000
commit1937104be15fbee565b8143bc2889ecd6b6206ac (patch)
treec627be8f36c02b47bb03757dd3c5d8627a7c1bd5 /usr.bin/tmux/cmd-copy-buffer.c
parentsync (diff)
downloadwireguard-openbsd-1937104be15fbee565b8143bc2889ecd6b6206ac.tar.xz
wireguard-openbsd-1937104be15fbee565b8143bc2889ecd6b6206ac.zip
Give each paste buffer a size member instead of requiring them to be
zero-terminated.
Diffstat (limited to 'usr.bin/tmux/cmd-copy-buffer.c')
-rw-r--r--usr.bin/tmux/cmd-copy-buffer.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/usr.bin/tmux/cmd-copy-buffer.c b/usr.bin/tmux/cmd-copy-buffer.c
index 3f6f5cb28a7..df27f46444e 100644
--- a/usr.bin/tmux/cmd-copy-buffer.c
+++ b/usr.bin/tmux/cmd-copy-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-copy-buffer.c,v 1.3 2009/07/26 12:58:44 nicm Exp $ */
+/* $OpenBSD: cmd-copy-buffer.c,v 1.4 2009/09/07 18:50:45 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -16,7 +16,10 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/types.h>
+
#include <stdlib.h>
+#include <string.h>
#include "tmux.h"
@@ -122,34 +125,38 @@ cmd_copy_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_copy_buffer_data *data = self->data;
struct paste_buffer *pb;
+ struct paste_stack *dst_ps, *src_ps;
+ u_char *pdata;
struct session *dst_session, *src_session;
u_int limit;
if ((dst_session = cmd_find_session(ctx, data->dst_session)) == NULL ||
(src_session = cmd_find_session(ctx, data->src_session)) == NULL)
return (-1);
+ dst_ps = &dst_session->buffers;
+ src_ps = &src_session->buffers;
if (data->src_idx == -1) {
- if ((pb = paste_get_top(&src_session->buffers)) == NULL) {
+ if ((pb = paste_get_top(src_ps)) == NULL) {
ctx->error(ctx, "no buffers");
return (-1);
}
} else {
- if ((pb = paste_get_index(&src_session->buffers,
- data->src_idx)) == NULL) {
+ if ((pb = paste_get_index(src_ps, data->src_idx)) == NULL) {
ctx->error(ctx, "no buffer %d", data->src_idx);
return (-1);
}
}
-
limit = options_get_number(&dst_session->options, "buffer-limit");
- if (data->dst_idx == -1) {
- paste_add(&dst_session->buffers, xstrdup(pb->data), limit);
- return (0);
- }
- if (paste_replace(&dst_session->buffers, data->dst_idx,
- xstrdup(pb->data)) != 0) {
+
+ pdata = xmalloc(pb->size);
+ memcpy(pdata, pb->data, pb->size);
+
+ if (data->dst_idx == -1)
+ paste_add(dst_ps, pdata, pb->size, limit);
+ else if (paste_replace(dst_ps, data->dst_idx, pdata, pb->size) != 0) {
ctx->error(ctx, "no buffer %d", data->dst_idx);
+ xfree(pdata);
return (-1);
}