From 9ef5cc1b1ba95578d1abb0f98dfdbe5169ab7674 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Tue, 7 Aug 2007 20:21:39 +0000 Subject: [PATCH] in copy_from_file(), fix potential segfault after uncutting one line of text with the mark on by properly preserving the beginning of the mark; also, make sure the mark is always properly positioned after uncutting one line of text with the mark on git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_2_0_branch/nano@4141 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 6 ++++++ src/nano.c | 27 +++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 889252e3..3bcacf5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -30,6 +30,12 @@ CVS code - - nano.c: version() - Display copyright notices. (DLR) + copy_from_file() + - Fix potential segfault after uncutting one line of text with + the mark on by properly preserving the beginning of the mark. + (DLR, found by Paul Goins) + - Make sure the mark is always properly positioned after + uncutting one line of text with the mark on. (DLR) - prompt.c: do_yesno_prompt() - Remove redundant check for NO_HELP's being FALSE. (DLR) diff --git a/src/nano.c b/src/nano.c index a190bcf4..58bafe5f 100644 --- a/src/nano.c +++ b/src/nano.c @@ -393,9 +393,22 @@ void copy_from_filestruct(filestruct *file_top, filestruct *file_bot) { filestruct *top_save; bool edittop_inside; +#ifndef NANO_TINY + bool right_side_up = FALSE; +#endif assert(file_top != NULL && file_bot != NULL); +#ifndef NANO_TINY + if (openfile->mark_set) { + filestruct *top, *bot; + size_t top_x, bot_x; + + mark_order((const filestruct **)&top, &top_x, + (const filestruct **)&bot, &bot_x, &right_side_up); + } +#endif + /* Partition the filestruct so that it contains no text, and keep * track of whether the top of the edit window is inside the * partition. */ @@ -410,11 +423,21 @@ void copy_from_filestruct(filestruct *file_top, filestruct *file_bot) while (openfile->filebot->next != NULL) openfile->filebot = openfile->filebot->next; - /* Restore the current line and cursor position. */ + /* Restore the current line and cursor position. If the mark begins + * inside the partition, adjust the mark coordinates to compensate + * for the change in the current line. */ openfile->current = openfile->filebot; openfile->current_x = strlen(openfile->filebot->data); - if (openfile->fileage == openfile->filebot) + if (openfile->fileage == openfile->filebot) { +#ifndef NANO_TINY + if (openfile->mark_set) { + openfile->mark_begin = openfile->current; + if (!right_side_up) + openfile->mark_begin_x += openfile->current_x; + } +#endif openfile->current_x += strlen(filepart->top_data); + } /* Get the number of characters in the copied text, and add it to * totsize. */ -- 2.39.5