=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-set-buffer.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- src/usr.bin/tmux/cmd-set-buffer.c 2014/10/20 22:29:25 1.20 +++ src/usr.bin/tmux/cmd-set-buffer.c 2015/08/29 09:25:00 1.21 @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-set-buffer.c,v 1.20 2014/10/20 22:29:25 nicm Exp $ */ +/* $OpenBSD: cmd-set-buffer.c,v 1.21 2015/08/29 09:25:00 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -42,9 +42,9 @@ { struct args *args = self->args; struct paste_buffer *pb; - char *pdata, *cause; - const char *bufname; - size_t psize, newsize; + char *bufdata, *cause; + const char *bufname, *olddata; + size_t bufsize, newsize; bufname = NULL; @@ -58,12 +58,11 @@ bufname = args_get(args, 'b'); if (bufname == NULL) { - pb = paste_get_top(); + pb = paste_get_top(&bufname); if (pb == NULL) { cmdq_error(cmdq, "no buffer"); return (CMD_RETURN_ERROR); } - bufname = pb->name; } if (paste_rename(bufname, args_get(args, 'n'), &cause) != 0) { @@ -79,37 +78,33 @@ cmdq_error(cmdq, "no data specified"); return (CMD_RETURN_ERROR); } - - psize = 0; - pdata = NULL; - pb = NULL; + bufsize = 0; + bufdata = NULL; + if ((newsize = strlen(args->argv[0])) == 0) return (CMD_RETURN_NORMAL); if (args_has(args, 'b')) { bufname = args_get(args, 'b'); pb = paste_get_name(bufname); - } else if (args_has(args, 'a')) { - pb = paste_get_top(); - if (pb != NULL) - bufname = pb->name; - } + } else if (args_has(args, 'a')) + pb = paste_get_top(&bufname); if (args_has(args, 'a') && pb != NULL) { - psize = pb->size; - pdata = xmalloc(psize); - memcpy(pdata, pb->data, psize); + olddata = paste_buffer_data(pb, &bufsize); + bufdata = xmalloc(bufsize); + memcpy(bufdata, olddata, bufsize); } - pdata = xrealloc(pdata, psize + newsize); - memcpy(pdata + psize, args->argv[0], newsize); - psize += newsize; + bufdata = xrealloc(bufdata, bufsize + newsize); + memcpy(bufdata + bufsize, args->argv[0], newsize); + bufsize += newsize; - if (paste_set(pdata, psize, bufname, &cause) != 0) { + if (paste_set(bufdata, bufsize, bufname, &cause) != 0) { cmdq_error(cmdq, "%s", cause); - free(pdata); + free(bufdata); free(cause); return (CMD_RETURN_ERROR); }