From 09f39cbec6c1d337517e22e0514e76daf9ce44ca Mon Sep 17 00:00:00 2001
From: Chris Allegretta <chrisa@asty.org>
Date: Mon, 5 Feb 2001 13:43:23 +0000
Subject: [PATCH] Fix for bugu #54

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@518 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 BUGS      |  8 ++++----
 ChangeLog |  3 +++
 cut.c     | 11 +++++------
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/BUGS b/BUGS
index d5c6cf38..b36caa75 100644
--- a/BUGS
+++ b/BUGS
@@ -94,11 +94,11 @@
   browser..) (52) [FIXED]
 - Alt speller argument (-s, --speller) does not take a string argument of
   more than one word. (53) [FIXED].
+- Cut to end cutting (-k) causes segfaults (try cutting "- Backup making
+  (filename~)?" line in TODO file) (discovred by
+  higuita@cadernoverde.com) (54) [FIXED].
+
 
 ** Open BUGS **
 
 $Id$
-- Cut to end cutting (-k) causes segfaults (try cutting "- Backup making
-  (filename~)?" line in TODO file) (discovred by
-  higuita@cadernoverde.com) (54).
-
diff --git a/ChangeLog b/ChangeLog
index b7cc3d43..49d53581 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
 CVS code -
 - configure.in:
 	- Autoconf compatibility fixes (Pavel Roskin)
+- cut.c:
+  do_cut_text()
+	- marked text cut fixes (Rocco) (Fixes bug #54).
 
 nano-0.9.99pre2 - 01/31/2001
 General
diff --git a/cut.c b/cut.c
index 1d9d2b76..5e8cba75 100644
--- a/cut.c
+++ b/cut.c
@@ -174,24 +174,23 @@ int do_cut_text(void)
     if (ISSET(MARK_ISSET)) {
 	if (current->lineno == mark_beginbuf->lineno) {
 	    tmp = copy_node(current);
-	    newsize = abs(strlen(&current->data[mark_beginx]) -
-			  strlen(&current->data[current_x]));
+	    newsize = abs(mark_beginx - current_x) + 1;
 
-	    tmpstr = nmalloc(newsize);
+	    tmpstr = nmalloc(newsize + 1);
 	    if (current_x < mark_beginx) {
 		strncpy(tmpstr, &current->data[current_x], newsize);
 		memmove(&current->data[current_x],
 			&current->data[mark_beginx],
-			strlen(&current->data[mark_beginx] - newsize));
+			strlen(&current->data[mark_beginx]) + 1);
 	    } else {
 		strncpy(tmpstr, &current->data[mark_beginx], newsize);
 		memmove(&current->data[mark_beginx],
 			&current->data[current_x],
-			strlen(&current->data[current_x] - newsize));
+			strlen(&current->data[current_x]) + 1);
 		current_x = mark_beginx;
 		update_cursor();
 	    }
-	    tmpstr[newsize] = 0;
+	    tmpstr[newsize - 1] = 0;
 	    tmp->data = tmpstr;
 	    add_to_cutbuffer(tmp);
 	    dump_buffer(cutbuffer);
-- 
GitLab