From 724950701a6ba84649975af89e7b840269b0a1eb Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Sat, 22 Feb 2014 16:46:27 +0000
Subject: [PATCH] Updating 'mark_begin' when mark and cursor are on the same
 line.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4591 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog  | 5 +++++
 src/nano.c | 9 +++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b6f4c1e8..2a3ec1e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-02-22  Benno Schulenberg  <bensberg@justemail.net>
+	* src/nano.c (move_to_filestruct) - Update the data in 'mark_begin'
+	when mark and cursor are on the same line.  This avoids a segfault
+	after M-A, right, M-T, left, ^K, or a hang when the left is left out.
+
 2014-02-22  Benno Schulenberg  <bensberg@justemail.net>
 	* src/nano.c (main) - Add two conditions on ENABLE_NANORC.
 	* src/files.c (close_buffer, do_insertfile) - Likewise.
diff --git a/src/nano.c b/src/nano.c
index a2b5d5d4..51545ebf 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -297,6 +297,7 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
     bool edittop_inside;
 #ifndef NANO_TINY
     bool mark_inside = FALSE;
+    bool same_line = FALSE;
 #endif
 
     assert(file_top != NULL && file_bot != NULL && top != NULL && bot != NULL);
@@ -314,7 +315,7 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
 	openfile->fileage->lineno && openfile->edittop->lineno <=
 	openfile->filebot->lineno);
 #ifndef NANO_TINY
-    if (openfile->mark_set)
+    if (openfile->mark_set) {
 	mark_inside = (openfile->mark_begin->lineno >=
 		openfile->fileage->lineno &&
 		openfile->mark_begin->lineno <=
@@ -323,6 +324,8 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
 		openfile->mark_begin_x >= top_x) &&
 		(openfile->mark_begin != openfile->filebot ||
 		openfile->mark_begin_x <= bot_x));
+	same_line = (openfile->mark_begin == openfile->fileage);
+    }
 #endif
 
     /* Get the number of characters in the text, and subtract it from
@@ -382,7 +385,9 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
     if (mark_inside) {
 	openfile->mark_begin = openfile->current;
 	openfile->mark_begin_x = openfile->current_x;
-    }
+    } else if (same_line)
+	/* update the content of this partially cut line */
+	openfile->mark_begin = openfile->current;
 #endif
 
     top_save = openfile->fileage;
-- 
GitLab