[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: EasyDiff on windows crash
From: |
Wolfgang Lux |
Subject: |
Re: EasyDiff on windows crash |
Date: |
Fri, 10 Aug 2012 18:34:13 +0200 |
Hi Riccardo
> gradually, I see in line 70 the array growing. After the third iteration I
> have:
> (gdb) po leftLineRangesArray
> ("-1", 89)
> (gdb) po leftLineRangesArray
> ("-1", 89, 89)
> (gdb) po leftLineRangesArray
> ("-1", 89, 89)
> (gdb) p end
> $3 = 89
> (gdb) p length
> $4 = 3258
>
> if I print out leftString, I get the whole file. Somehow it looks stuck,
> doesn't it? I iterated manually for a dozen of times: 89.... probably at some
> point something corrupts.
>
> If I print out "end" on Unix I get an increasing progression towards the
> whole size of the file. If I try on Windows, it gets to 89 and remains stuck
> there for infinity.
> Is there a but in our getLineStart ?
>
> I understand the code wants to progressively find all line endings by looking
> in a larger and larger range. Although I find the code strange, since it uses
> a Range of 0 length,
There is nothing strange about this code; you seem to misunderstand how the
method -getLineStart:end: contentsEnd:forRange: works. For the given range it
returns the smallest enclosing range that begins and ends at a line break,
where the contentsEnd: argument returns the position before and the end:
argument the position after the line end.
Now the loop did work on Unix because a line end is always just a single
linefeed character, so using contentsEnd + 1 gives a position in the next line.
On the other it breaks on Windows when a line ends with a CR-LF combination.
Then contentsEnd + 1 is just in the middle of that combination and the next
time the method returns exactly the same line.
> I rewrote the code and now it appears to work on both unix and windows...
> what do you think? I tlooks much simpler to me... "inspired" from the net :)
> It doesn't have the exceptions and it looks only in a specified range, it
> might be more efficient. Should i commit?
Yes. Your fix is exactly the right thing to do. And it would be worth moving
this code into a method or a function rather than having it duplicate for the
left and right files.
> However, I smell an NSString bug and you?
Given that the loop did not make any progress but continues adding elements to
the leftLineRange array, I'd suspect that the initial segment violation was
really a heap overflow.
Wolfgang