From c272de7cbafa343f0e2fc25beb66ed0b924f336f Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Mon, 7 Sep 2009 23:48:54 +0000 Subject: Sync OpenBSD patchset 318: Give each paste buffer a size member instead of requiring them to be zero-terminated. --- cmd-copy-buffer.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'cmd-copy-buffer.c') diff --git a/cmd-copy-buffer.c b/cmd-copy-buffer.c index 426d7778..30731d14 100644 --- a/cmd-copy-buffer.c +++ b/cmd-copy-buffer.c @@ -1,4 +1,4 @@ -/* $Id: cmd-copy-buffer.c,v 1.3 2009-07-28 22:12:16 tcunha Exp $ */ +/* $Id: cmd-copy-buffer.c,v 1.4 2009-09-07 23:48:54 tcunha Exp $ */ /* * Copyright (c) 2009 Tiago Cunha @@ -16,7 +16,10 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include + #include +#include #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); } -- cgit v1.2.3