View Issue Details

IDProjectCategoryView StatusLast Update
0038185LazarusIDEpublic2020-12-13 15:42
ReporterDomingo Galmés Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformx64OSwindows 
Product Version2.1 (SVN) 
Summary0038185: Ide freezes when compare files
DescriptionThe IDE freezes when compare files with empty lines before text.

Options checked: Ignore spaces at end of line.

file1 file2
---------------------------------------
one
two one
                               two
---------------------------------------
Steps To ReproduceIn Tools/Compare file ...

select file1.txt and file2.txt.

After selecting the files the ide freezes.

Options checked: Ignore spaces at end of line.
TagsNo tags attached.
Fixed in Revisionr64199
LazTarget-
WidgetsetWin32/Win64
Attached Files

Activities

Domingo Galmés

2020-12-08 12:34

reporter  

file1.txt (8 bytes)   
one
two
file1.txt (8 bytes)   
file2.txt (10 bytes)   
one
two
file2.txt (10 bytes)   

Juha Manninen

2020-12-09 09:54

developer   ~0127471

Last edited: 2020-12-09 10:19

View 2 revisions

I cannot reproduce. Your attached files give an empty diff. When I change them as in the issue's Description, I get the diff below. No freeze.
I tested on Linux.
You should debug the freeze. Does CPU load go to 100%? Then the code runs an eternal loop.
procedure TDiffOutput.FindNextEqualLine and function TDiffOutput.CreateTextDiff in unit DiffPatch have repeat .. until loops. Open project lazarus.lpi and run it. (FYI: you cannot build using lazarus.lpi). Place breakpoints to those methods.


***************
*** 1,5 ****
! one
! two one
--- 1,6 ----
  
  
! two

Domingo Galmés

2020-12-09 14:32

reporter   ~0127479

Hi, the bug tracker formated the files wrong.

File 1 has 2 lines
one
two

File 2 has 3 lines
blank line
one
two

I have debugged in windows and enters in infinite loop in the

Line 620 of DiffPatch.pas
  finally
    repeat
      EqualLine1:=Cur1;
      EqualLine2:=Cur2;
      // chomp empty lines at end
      fPart1.GetPrevLineExtends(Cur1);
      fPart2.GetPrevLineExtends(Cur2);
    until not LinesAreEqual(Cur1,Cur2);
  end;
end;

I have made a project for testing and in windows enters in the loop and don't exit.

My interest in this code is for merge de output of Jedi Code Format with the original code like applyng a patch instead of make a full copy of the formated text.

When i have more free time i will look again to see if i can find the problem.
project1.zip (110,280 bytes)

jamie philbrook

2020-12-09 14:35

reporter   ~0127480

Please try to revert back to 64172 and see what happens then.

Juha Manninen

2020-12-09 16:10

developer   ~0127484

> Hi, the bug tracker formated the files wrong.
I used the attached files. No freeze with them either on Linux. Maybe it depends on line endings. You will figure it out by debugging.

@Jamie
r64172 is not in Lazarus trunk. It must be in another branch, maybe fixes_2_0.
Jamie, why don't you tell us what happens with r64172?

Ondrej Pokorny

2020-12-09 16:50

developer   ~0127490

Should be fixed now. Please reopen if not fixed.

Domingo Galmés

2020-12-10 21:44

reporter   ~0127514

I have tried it with the latest version and the problem continues.
I think the problem is with the treatment of the end of lines $0d $0a in windows in the functions of DiffPatch.pas not with the LCL or with the drawing interface and it has no relation with 0038190 0038191.

Juha Manninen

2020-12-11 00:15

developer   ~0127526

Can you create a patch to fix it please.

jamie philbrook

2020-12-11 00:49

reporter   ~0127528

Last edited: 2020-12-11 01:51

View 3 revisions

I have tried numerus combinations of files and I can't get any lockup..
it could be some uninitialized variable somewhere or difference of compilers ?

I don't see that in the note unless I missed it?

There are many using the TRUNK compiler 3.3.x for their work so I would first ask that question.

EDIT:
Although I can't reproduce it here however, I did look at that code and it appears if the search for unequal lines in that Repeat Loop makes it to line 0000001 and the two lines are not the same, it can repeat it self.

In the GetPrevLineExtends(Cur1) for example, It is testing for the line number and if it makes it to < 1 Then it simple returns.
there is no check being done in the Repeat.... Until for a line number < 1 to terminate the loop.

so it appears if it makes it all the way back to the start of the document and the two are not the same I guess it just loops.

That is what I got out of looking at the code, I didn't put the IDE in debug state to test that theory..

Domingo Galmés

2020-12-11 23:22

reporter   ~0127547

This patch solves the problem.

As Jamie said testing for lineNumber<1 to terminate the loop solves the freeze.

The compiler version used es 3.2.0 for i386-Win32 and the trunk of lazarus.
FileCompareFreezes.patch (693 bytes)   
From 1f5be8656292a250ef140e84a0222ebf0ce55b74 Mon Sep 17 00:00:00 2001
From: DomingoGP <dgalmesp@gmail.com>
Date: Fri, 11 Dec 2020 23:15:43 +0100
Subject: [PATCH] solves freeze when compare files.

---
 ide/diffpatch.pas | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ide/diffpatch.pas b/ide/diffpatch.pas
index 4142fedd7e..ac89b2e972 100644
--- a/ide/diffpatch.pas
+++ b/ide/diffpatch.pas
@@ -616,6 +616,8 @@ begin
       // chomp empty lines at end
       fPart1.GetPrevLineExtends(Cur1);
       fPart2.GetPrevLineExtends(Cur2);
+      if (Cur1.LineNumber < 1) or (Cur2.LineNumber < 1) then
+        break;
     until not LinesAreEqual(Cur1,Cur2);
   end;
 end;
-- 
2.29.1.windows.1

FileCompareFreezes.patch (693 bytes)   

Juha Manninen

2020-12-12 19:46

developer   ~0127575

Applied, thanks.
It remains a mystery why the freeze did not happen in every Windows system.

Domingo Galmés

2020-12-13 15:42

reporter   ~0127586

Thanks for apply.

Issue History

Date Modified Username Field Change
2020-12-08 12:34 Domingo Galmés New Issue
2020-12-08 12:34 Domingo Galmés File Added: file1.txt
2020-12-08 12:34 Domingo Galmés File Added: file2.txt
2020-12-09 09:54 Juha Manninen Note Added: 0127471
2020-12-09 10:19 Juha Manninen Note Edited: 0127471 View Revisions
2020-12-09 14:32 Domingo Galmés Note Added: 0127479
2020-12-09 14:32 Domingo Galmés File Added: project1.zip
2020-12-09 14:35 jamie philbrook Note Added: 0127480
2020-12-09 16:10 Juha Manninen Note Added: 0127484
2020-12-09 16:50 Ondrej Pokorny Assigned To => Ondrej Pokorny
2020-12-09 16:50 Ondrej Pokorny Status new => resolved
2020-12-09 16:50 Ondrej Pokorny Resolution open => fixed
2020-12-09 16:50 Ondrej Pokorny LazTarget => -
2020-12-09 16:50 Ondrej Pokorny Widgetset Win32/Win64 => Win32/Win64
2020-12-09 16:50 Ondrej Pokorny Note Added: 0127490
2020-12-09 16:53 Ondrej Pokorny Relationship added has duplicate 0038191
2020-12-09 16:53 Ondrej Pokorny Relationship added has duplicate 0038190
2020-12-10 21:44 Domingo Galmés Status resolved => assigned
2020-12-10 21:44 Domingo Galmés Resolution fixed => open
2020-12-10 21:44 Domingo Galmés Note Added: 0127514
2020-12-11 00:14 Juha Manninen Relationship deleted has duplicate 0038191
2020-12-11 00:14 Juha Manninen Relationship deleted has duplicate 0038190
2020-12-11 00:15 Juha Manninen Note Added: 0127526
2020-12-11 00:49 jamie philbrook Note Added: 0127528
2020-12-11 01:49 jamie philbrook Note Edited: 0127528 View Revisions
2020-12-11 01:51 jamie philbrook Note Edited: 0127528 View Revisions
2020-12-11 23:22 Domingo Galmés Note Added: 0127547
2020-12-11 23:22 Domingo Galmés File Added: FileCompareFreezes.patch
2020-12-12 19:41 Juha Manninen Assigned To Ondrej Pokorny => Juha Manninen
2020-12-12 19:46 Juha Manninen Status assigned => resolved
2020-12-12 19:46 Juha Manninen Resolution open => fixed
2020-12-12 19:46 Juha Manninen Fixed in Revision => r64199
2020-12-12 19:46 Juha Manninen Widgetset Win32/Win64 => Win32/Win64
2020-12-12 19:46 Juha Manninen Note Added: 0127575
2020-12-13 15:42 Domingo Galmés Status resolved => closed
2020-12-13 15:42 Domingo Galmés Note Added: 0127586