[fpc-devel] New sorting routines

C Western l at c-m-w.me.uk
Mon Feb 4 15:03:07 CET 2019


On 04/02/2019 12:26, Nikolay Nikolov wrote:
>
> On 2/3/19 11:22 PM, C Western wrote:
>> I suspect the new sorting routines need some work - lazarus compiled 
>> with the latest trunk hangs on start up, and it looks like an 
>> infinite loop in sorting. Stack trace below.
>
> Even though the sort routine did slightly change, I believe this 
> exposes a bug in lazarus. The CompareBinary routine in 
> syneditmarkuphighall.pp returns -1 when the strings are equal, while 
> it should return 0 in this case. This is like having two elements in 
> the array, for which (a<b) and (b<a) are both true at the same time. 
> The Compare function, passed to the sort algorithms must satisfy the 
> mathematical properties of comparisons, otherwise the result is 
> undefined (whether it should results in a hang (like in this case), or 
> in a bad sort (like in the previous variation of the algorithm) is a 
> separate discussion).
>
> The attached patch fixes this.
>
I am happy to confirm lazarus starts with the patch applied.

Many thanks

Colin




More information about the fpc-devel mailing list