bugGNU nano - Bugs: bug #54573, full-justify can go into an...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #54573: full-justify can go into an infinite loop when the last line isn't a paragraph

Submitter:  David Lawrence Ramsey <dolorous>
Submitted:  Sun 26 Aug 2018 04:07:56 PM UTC
   
 
Severity:  4 - Important Status:  Fixed
Assigned to:  dolorous Open/Closed:  Closed

Jump to the original submission

Mon 10 Sep 2018 05:52:21 PM UTC, comment #9: 

Released in 3.0.

Benno Schulenberg <bens>
Group administrator
Mon 27 Aug 2018 06:31:12 PM UTC, comment #8: 

Thanks for the patch.  Applied, with a tweaked commit message, and pushed, commit 93c8e316.

Benno Schulenberg <bens>
Group administrator
Sun 26 Aug 2018 11:22:58 PM UTC, comment #7: 

Attached a new version of the patch, unchanged except for an improved commit message (which also references the bug number, as it should have before).  Sorry for the mess.

(file #44871)

David Lawrence Ramsey <dolorous>
Group Member
Sun 26 Aug 2018 06:21:18 PM UTC, comment #6: 

And, to be clear, it fixes the incorrect behavior with justify as well as the hang with full-justify.

David Lawrence Ramsey <dolorous>
Group Member
Sun 26 Aug 2018 06:12:08 PM UTC, comment #5: 

The fix turned out to be easier than I thought, and works with your new example as well.  Attached.

(file #44870)

David Lawrence Ramsey <dolorous>
Group Member
Sun 26 Aug 2018 05:38:48 PM UTC, comment #4: 

Wow, a hang!  Superb find!  :)

(I don't like to have to download a file with which to reproduce a bug.  It's much better to describe what to do with a file we all have: with README, for example.  To reproduce the original submission: run 'nano --ignore --nonew +9999 README' and type: <Tab> M-J.  Result: hang.)

I've tested 2.9.1 and 2.8.1 and 2.6.1 -- the bug occurs in all.

Benno Schulenberg <bens>
Group administrator
Sun 26 Aug 2018 05:29:54 PM UTC, comment #3: 

The underlying problems are caused by the paragraph detection.  This can be demonstrated as follows:

1. Run:

nano -I --nonewlines justify-bug.txt

2. Press ^W^O to move down a paragraph.  The cursor moves from the beginning of line 1 to the beginning of line 2.  This is expected.

3. Press ^W^O to move down a paragraph again.  The cursor moves from the beginning of line 2 to the end of line 2.  This is expected.

4. Press ^W to move up a paragraph.  The cursor moves from the end of line 2 to the beginning of line 1.  This is expected (and matches what Pico does in these circumstances, except for Pico's being unable to turn the magicline off).

The case in step (4) is the root of what's going on.

David Lawrence Ramsey <dolorous>
Group Member
Sun 26 Aug 2018 05:15:01 PM UTC, comment #2: 

Addendum:, the bug manifests differently (not an infinite loop, but still incorrect behavior) when manually justifying the entire file, step by step.  Specifically:

1. Run:

nano -I --nonewlines justify-bug.txt

2. Press Ctrl-J to justify the first line.  The double space turns into a single space, and the cursor moves to the line after the end of that paragraph: the second line.  This is expected.

3. Press Ctrl-J to justify the second line.  Since it consists only of spaces, there's nothing to justify.  The cursor stays where it is, and the line is unchanged.  This is not expected, and is the real problem: nano should put the cursor at the end of the second line, since that's the closest thing to the end of the paragraph when there isn't one, and justify is supposed to move past non-paragraph text that it can't affect.

(The justification for the proposed behavior in (3) is also based on what nano does when the last line of the file is part of a paragraph.  If you repeat the steps in the initial report with the attached file justify-bug2.txt, which contains only the first line of justify-bug.txt, you can see this: the double space turns into a single space, and the cursor moves to the end of the line, which is the closest thing to the line after the end of that paragraph.)

(file #44868)

David Lawrence Ramsey <dolorous>
Group Member
Sun 26 Aug 2018 04:58:25 PM UTC, comment #1: 

Argh; attached proper version of justify-bug.txt.

(file #44867)

David Lawrence Ramsey <dolorous>
Group Member
Sun 26 Aug 2018 04:07:56 PM UTC, original submission:  

This occurs with current git (80bea3e), 2.9.8, and 2.9.7 so far.  I haven't had time yet to check how far back it goes, but the last major changes to the justify code were the recursion changes after 2.9.7, so those apparently aren't the cause.

The bug can be reproduced as follows:

1. With the attached file, run:

nano -I --nonewlines justify-bug.txt

(Note that the attached file has no final newline, and it's made up of only whitespace, so it's not part of a paragraph.)

2. Press M-J to do a full-justify.  nano goes into an infinite loop in the find_paragraph() call inside do_justify(); on the last line, it tries to go backward to find the beginning of the paragraph, and ends up on the first line of the first line (the previous paragraph), so it tries to go forward to find the end of the paragraph, and so on.

David Lawrence Ramsey <dolorous>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bens (Posted a comment)
  • -email is unavailable- added by dolorous (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-09-10 bens Open/ClosedOpen Closed
    2018-08-27 bens StatusNone Fixed
        Assigned toNone dolorous
    2018-08-26 dolorous Attached File- Added 0001-justify-add-another-check-for-being-in-a-paragraph-t.patch, #44871
    2018-08-26 dolorous Attached File- Added 0001-justify-add-another-check-for-being-in-a-paragraph-t.patch, #44870
    2018-08-26 bens Severity3 - Normal 4 - Important
    2018-08-26 dolorous Attached File- Added justify-bug2.txt, #44868
    2018-08-26 dolorous Attached File#44866 Removed
    2018-08-26 dolorous Attached File- Added justify-bug.txt, #44867
    2018-08-26 dolorous Attached File- Added justify-bug.txt, #44866

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code