Lazarus

Free Pascal => General => Topic started by: shyakocat on November 21, 2019, 03:43:11 pm

Title: It seems that Free Pascal 3.0.4 Sort has something wrong?
Post by: shyakocat on November 21, 2019, 03:43:11 pm
Today I found a fault(maybe?) of fpc 3.0.4 when I was solving an ACM problem.

I uses TOrderingArrayUtils to Sort an TVector,but it turns to RunTimeError at times.Then I view the source of garrayutils.pp on github.

Code: Pascal  [Select][+][-]
  1.     while (cur <> 0) AND (TCompare.c(Arr[l],Arr[cur])) do
  2.     begin
  3.       temp:=Arr[cur];
  4.       Arr[cur]:=Arr[l];
  5.       Arr[l]:=temp;
  6.       cur:=l;
  7.       l:=Parent(cur-Start)+Start;
  8.     end;

I think the
Code: Pascal  [Select][+][-]
  1. cur <> 0
should be
Code: Pascal  [Select][+][-]
  1. cur > Start
.Otherwise it will access a wrong position of the heap because (cur-Start) doesn't have a Parent.

But I'm not sure.Can anyone prove it and contact the authority?
Title: Re: It seems that Free Pascal 3.0.4 Sort has something wrong?
Post by: guest64953 on November 21, 2019, 05:45:21 pm
Today I found a fault(maybe?) of fpc 3.0.4 when I was solving an ACM problem.

I uses TOrderingArrayUtils to Sort an TVector,but it turns to RunTimeError at times.Then I view the source of garrayutils.pp on github.

Code: Pascal  [Select][+][-]
  1.     while (cur <> 0) AND (TCompare.c(Arr[l],Arr[cur])) do
  2.     begin
  3.       temp:=Arr[cur];
  4.       Arr[cur]:=Arr[l];
  5.       Arr[l]:=temp;
  6.       cur:=l;
  7.       l:=Parent(cur-Start)+Start;
  8.     end;

I think the
Code: Pascal  [Select][+][-]
  1. cur <> 0
should be
Code: Pascal  [Select][+][-]
  1. cur > Start
.Otherwise it will access a wrong position of the heap because (cur-Start) doesn't have a Parent.

But I'm not sure.Can anyone prove it and contact the authority?

I don't think this is the right sub forum to post this.
Title: Re: It seems that Free Pascal 3.0.4 Sort has something wrong?
Post by: Martin_fr on November 21, 2019, 07:04:24 pm
Moved the topic to better board
Title: Re: It seems that Free Pascal 3.0.4 Sort has something wrong?
Post by: BrunoK on November 21, 2019, 09:13:12 pm
Where is the better board ?
Title: Re: It seems that Free Pascal 3.0.4 Sort has something wrong?
Post by: Martin_fr on November 21, 2019, 09:46:00 pm
It is now in "Free Pascal ยป General", instead of "Third Party announcements"
Please go back to the orig topic, or otherwise open your own thread for "moving topic" related questions"
TinyPortal © 2005-2018