From e7ee63f2717c2ca91e25008799f55c2b2056b1de Mon Sep 17 00:00:00 2001
From: Chris Allegretta <chrisa@asty.org>
Date: Tue, 23 Oct 2001 12:58:42 +0000
Subject: [PATCH] - cut.c: cut_marked_segment() - Fix off-by one in mem
 allocation

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@868 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog | 2 ++
 cut.c     | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 26021829..d97d62a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,8 @@ CVS code -
 	   replaces cuttingpartialline).
   do_uncut_text()
 	- Similar display fixes (David Lawrence Ramsey).
+  cut_marked_segment()
+	- Fix off-by one in mem allocation.
 - faq.html
 	- Removed nano-editor.org FTP site address [deprecated] and added
 	the GNU one.
diff --git a/cut.c b/cut.c
index aab6d44f..5bc80f12 100644
--- a/cut.c
+++ b/cut.c
@@ -141,7 +141,7 @@ void cut_marked_segment(filestruct * top, int top_x, filestruct * bot,
     /* Now, paste bot[bot_x] into top[top_x] */
     if (destructive) {
 
-	tmpstr = charalloc(strlen(top->data) + strlen(&bot->data[bot_x]));
+	tmpstr = charalloc(top_x + strlen(&bot->data[bot_x]) + 1);
 	strncpy(tmpstr, top->data, top_x);
 	strcpy(&tmpstr[top_x], &bot->data[bot_x]);
 	free(top->data);
-- 
GitLab