diff --git a/ChangeLog b/ChangeLog index b80ba67476b6bccb948cb7e91c10a7e81df40002..24f3edf83342c600d61ebd2426a4f12fae3938af 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 4ecbddc7b2bfa0b6ed329f6ff69c64d170a8c4b8..aa0be72fbdec6dacc18928869bbf0e001b226a64 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 {