Recent

Author Topic: It seems that Free Pascal 3.0.4 Sort has something wrong?  (Read 341 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?

hunghung

  • Full Member
  • ***
  • Posts: 141
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: 5800
    • 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

  • Full Member
  • ***
  • Posts: 191
  • 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 ?
Lazarus trunk r. 62137/27.10.2019 (+/- patches regarding TScrollBar, IntitalSetupDialog, Options.Environment options, SearchResults).  Lazarus 3.0.6 raw from svn.
FPC 3.0.4 32 bits. (+heaptrc with leaked ClassName+Revisited TList) , Windows 10 Pro x64 (v. 1903 / 18362.418)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5800
    • 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"