From b736ab228166f2d8e052b7d4d34c75ac76a04b7e Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 13 May 2014 22:54:18 +0000 Subject: [PATCH] Don't allow multiple buffers with the same name, from Thomas Adam. --- usr.bin/tmux/paste.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/usr.bin/tmux/paste.c b/usr.bin/tmux/paste.c index 1f9626fa56f..bfd531c9bfd 100644 --- a/usr.bin/tmux/paste.c +++ b/usr.bin/tmux/paste.c @@ -1,4 +1,4 @@ -/* $OpenBSD: paste.c,v 1.19 2014/05/13 07:34:35 nicm Exp $ */ +/* $OpenBSD: paste.c,v 1.20 2014/05/13 22:54:18 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -176,7 +176,7 @@ paste_add(char *data, size_t size) int paste_rename(const char *oldname, const char *newname, char **cause) { - struct paste_buffer *pb; + struct paste_buffer *pb, *pb_new; if (cause != NULL) *cause = NULL; @@ -195,7 +195,14 @@ paste_rename(const char *oldname, const char *newname, char **cause) pb = paste_get_name(oldname); if (pb == NULL) { if (cause != NULL) - xasprintf(cause, "no buffer %s", oldname); + xasprintf(cause, "no buffer %s", oldname); + return (-1); + } + + pb_new = paste_get_name(newname); + if (pb_new != NULL) { + if (cause != NULL) + xasprintf(cause, "buffer %s already exists", newname); return (-1); } -- 2.20.1