Recent

Author Topic: It seems that Free Pascal 3.0.4 Sort has something wrong?  (Read 1234 times)

shyakocat

  • Newbie
  • Posts: 3
It seems that Free Pascal 3.0.4 Sort has something wrong?
« 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?

guest64953

  • Guest
Re: It seems that Free Pascal 3.0.4 Sort has something wrong?
« Reply #1 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.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9855
  • Debugger - SynEdit - and more
    • wiki
Re: It seems that Free Pascal 3.0.4 Sort has something wrong?
« Reply #2 on: November 21, 2019, 07:04:24 pm »
Moved the topic to better board

BrunoK

  • Sr. Member
  • ****
  • Posts: 452
  • Retired programmer
Re: It seems that Free Pascal 3.0.4 Sort has something wrong?
« Reply #3 on: November 21, 2019, 09:13:12 pm »
Where is the better board ?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9855
  • Debugger - SynEdit - and more
    • wiki
Re: It seems that Free Pascal 3.0.4 Sort has something wrong?
« Reply #4 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