From 68ebb61fb143fbb79b68c461ae0d295a0546613f Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sat, 4 Dec 2004 17:36:14 +0000 Subject: [PATCH] fix potential segfault when doing a full justify git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2156 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 4 ++++ src/nano.c | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7175cae8..e95baa55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -62,6 +62,10 @@ CVS code - do_justify() - For consistency, preserve placewewant if we didn't unjustify instead of setting it to 0. (DLR) + - When justifying the entire file, properly break out of the + loop if there are no more paragraphs after the current one and + the paragraph search left us on the magicline, so as to avoid + a segfault. (DLR) - winio.c: unget_kbinput() - Remove the wide character handling, as it didn't work properly diff --git a/src/nano.c b/src/nano.c index 3408b79b..9cdfc711 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2771,15 +2771,15 @@ void do_justify(bool full_justify) /* Find the first line of the paragraph to be justified. That * is the start of this paragraph if we're in one, or the start * of the next otherwise. Save the quote length and paragraph - * length (number of lines). Don't refresh the screen yet - * (since we'll do that after we justify). If the search failed - * and we're justifying the whole file, move the last line of - * the text we're justifying to just before the magicline, which - * is where it'll be anyway if we've searched the entire file, - * and break out of the loop; otherwise, refresh the screen and + * length (number of lines). Don't refresh the screen yet, + * since we'll do that after we justify. If the search + * failed, we're justifying the whole file, and the search + * didn't leave us on the last line of the file, set the last + * line of the text to be justified to the last line of the file + * and break out of the loop. Otherwise, refresh the screen and * get out. */ if (do_para_search("e_len, &par_len)) { - if (full_justify) { + if (full_justify && current != filebot) { last_par_line = filebot; break; } else {