From 102d01da6cd3c19f2e2635ea33cd6d8508c60fa2 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Thu, 17 Mar 2005 04:48:14 +0000 Subject: [PATCH] fix justify code regression: if we're justifying the entire file, and we haven't found any paragraph(s), we should refresh the screen and get out instead of breaking out of the loop and acting as though we've justified something, so as to avoid a segfault git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2384 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 6 +++--- src/nano.c | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index b80ba674..24f3edf8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -236,9 +236,9 @@ CVS code - - 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) + loop if we've found at least one paragraph, there are no more + paragraphs after the current one, and the paragraph search + left us on the magicline. This avoids a segfault. (DLR) do_input() - Add finished parameter, used to indicate when we run or try to run a function associated with a shortcut. (DLR) diff --git a/src/nano.c b/src/nano.c index 4ecbddc7..aa0be72f 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2958,14 +2958,19 @@ void do_justify(bool full_justify) * 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, 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. */ + * since we'll do that after we justify. + * + * If the search failed, we do one of two things. If we're + * justifying the whole file, we've found at least one + * paragraph, and the search didn't leave us on the last line of + * the file, it means that we should justify all the way to the + * last line of the file, so set the last line of the text to be + * justified to the last line of the file and break out of the + * loop. Otherwise, it means that there are no paragraph(s) to + * justify, so refresh the screen and get out. */ if (!find_paragraph("e_len, &par_len)) { - if (full_justify && first_par_line != filebot) { + if (full_justify && first_par_line != NULL && + first_par_line != filebot) { last_par_line = filebot; break; } else { -- 2.39.5