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