Recent

Author Topic: Lazarus/FreePascal Bug  (Read 918 times)

JgQDev

  • New member
  • *
  • Posts: 9
Lazarus/FreePascal Bug
« on: February 13, 2026, 02:49:24 am »
Hello Everyone

I think Ive found a bug
The ((8*Length(num))-1) on the For-Loop, exits the Function/Procedure instead of continuing
Is anyone has this bug

num = Array of Byte;
nCount = Integer;
nCountr = Real;
Code: Pascal  [Select][+][-]
  1.   if(isLeft=False)then begin
  2.     for i:=0 to ((8*Length(num))-1)do begin
  3.       nCount:=i-PaceBaseOne;
  4.       if(nCount>-1)then begin
  5.         nCountr:=i/7;
  6.         if(Length(TArr1)=0)then SetLength(TArr1,Length(TArr1)+1);
  7.         if(nCountr=RR(nCountr))then bool1:=True;
  8.         if(self.IsBitSet(num[RR(i/8)],i)=True)then
  9.           self.SetBit(TArr1[RR(nCount/8)],nCount);
  10.       end;
  11.       if(bool1=True)then SetLength(TArr1,Length(TArr1)+1);
  12.       bool1:=False;
  13.     end;
  14.     bool1:=True;
  15.   end else  
  16.   //more code
  17.  
« Last Edit: February 13, 2026, 02:51:59 am by JgQDev »

creaothceann

  • Sr. Member
  • ****
  • Posts: 278
Re: Lazarus/FreePascal Bug
« Reply #1 on: February 13, 2026, 07:21:15 am »
First of all, formatting...

Then, enable the debug options in the project (menu | Project | Project Options... | Compiler Options | Debugging) and step through the program line-by-line.

Code: Pascal  [Select][+][-]
  1. if (not isLeft) then begin
  2.         {added code:} if (((8 * Length(num)) - 1) < 0) then ShowMessage('!');
  3.         for i := 0 to ((8 * Length(num)) - 1) do begin
  4.                 nCount := i - PaceBaseOne;
  5.                 if (nCount > -1) then begin
  6.                         nCountr := i / 7;
  7.                         if (Length(TArr1) = 0) then SetLength(TArr1, Length(TArr1) + 1);
  8.                         if (nCountr = RR(nCountr)) then bool1 := True;
  9.                         if Self.IsBitSet(num[RR(i / 8)], i) then Self.SetBit(TArr1[RR(nCount / 8)], nCount);
  10.                 end;
  11.                 if bool1 then SetLength(TArr1, Length(TArr1) + 1);
  12.                 bool1 := False;
  13.         end;
  14.         bool1 := True;
  15. end else begin
  16.         // more code
  17. end;
  18.  

440bx

  • Hero Member
  • *****
  • Posts: 6148
Re: Lazarus/FreePascal Bug
« Reply #2 on: February 13, 2026, 08:43:28 am »
There is something to be said for formatting... here is another way to format that code:
Code: Pascal  [Select][+][-]
  1.  
  2. if not isLeft then
  3. begin
  4.   { added code: } if ((8 * Length(num)) - 1) < 0 then ShowMessage('!');
  5.  
  6.   for i := 0 to (8 * Length(num)) - 1 do
  7.   begin
  8.     nCount := i - PaceBaseOne;
  9.  
  10.     if nCount > -1 then
  11.     begin
  12.       nCountr := i / 7;
  13.  
  14.       if Length(TArr1) = 0 then SetLength(TArr1, Length(TArr1) + 1);
  15.       if nCountr = RR(nCountr)) then bool1 := True;
  16.  
  17.       if Self.IsBitSet(num[RR(i / 8)], i) then
  18.       begin
  19.         Self.SetBit(TArr1[RR(nCount / 8)], nCount);
  20.       end;
  21.     end;
  22.  
  23.     if bool1 then SetLength(TArr1, Length(TArr1) + 1);
  24.     bool1 := FALSE;
  25.   end;
  26.  
  27.   bool1 := TRUE;
  28. end
  29. else
  30. begin
  31.   // more code
  32. end;
  33.  
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

JgQDev

  • New member
  • *
  • Posts: 9
Re: Lazarus/FreePascal Bug
« Reply #3 on: February 13, 2026, 09:52:15 am »
First of all, formatting...

Then, enable the debug options in the project (menu | Project | Project Options... | Compiler Options | Debugging) and step through the program line-by-line.

Code: Pascal  [Select][+][-]
  1. if (not isLeft) then begin
  2.         {added code:} if (((8 * Length(num)) - 1) < 0) then ShowMessage('!');
  3.         for i := 0 to ((8 * Length(num)) - 1) do begin
  4.                 nCount := i - PaceBaseOne;
  5.                 if (nCount > -1) then begin
  6.                         nCountr := i / 7;
  7.                         if (Length(TArr1) = 0) then SetLength(TArr1, Length(TArr1) + 1);
  8.                         if (nCountr = RR(nCountr)) then bool1 := True;
  9.                         if Self.IsBitSet(num[RR(i / 8)], i) then Self.SetBit(TArr1[RR(nCount / 8)], nCount);
  10.                 end;
  11.                 if bool1 then SetLength(TArr1, Length(TArr1) + 1);
  12.                 bool1 := False;
  13.         end;
  14.         bool1 := True;
  15. end else begin
  16.         // more code
  17. end;
  18.  

This still exits the function/procedure

Zvoni

  • Hero Member
  • *****
  • Posts: 3305
Re: Lazarus/FreePascal Bug
« Reply #4 on: February 13, 2026, 09:56:52 am »
First of all, formatting...

Then, enable the debug options in the project (menu | Project | Project Options... | Compiler Options | Debugging) and step through the program line-by-line.

Code: Pascal  [Select][+][-]
  1. if (not isLeft) then begin
  2.         {added code:} if (((8 * Length(num)) - 1) < 0) then ShowMessage('!');
  3.         for i := 0 to ((8 * Length(num)) - 1) do begin
  4.                 nCount := i - PaceBaseOne;
  5.                 if (nCount > -1) then begin
  6.                         nCountr := i / 7;
  7.                         if (Length(TArr1) = 0) then SetLength(TArr1, Length(TArr1) + 1);
  8.                         if (nCountr = RR(nCountr)) then bool1 := True;
  9.                         if Self.IsBitSet(num[RR(i / 8)], i) then Self.SetBit(TArr1[RR(nCount / 8)], nCount);
  10.                 end;
  11.                 if bool1 then SetLength(TArr1, Length(TArr1) + 1);
  12.                 bool1 := False;
  13.         end;
  14.         bool1 := True;
  15. end else begin
  16.         // more code
  17. end;
  18.  

This still exits the function/procedure
Then the Length of your num-array is zero
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

JgQDev

  • New member
  • *
  • Posts: 9
Re: Lazarus/FreePascal Bug
« Reply #5 on: February 13, 2026, 10:02:34 am »
First of all, formatting...

Then, enable the debug options in the project (menu | Project | Project Options... | Compiler Options | Debugging) and step through the program line-by-line.

Code: Pascal  [Select][+][-]
  1. if (not isLeft) then begin
  2.         {added code:} if (((8 * Length(num)) - 1) < 0) then ShowMessage('!');
  3.         for i := 0 to ((8 * Length(num)) - 1) do begin
  4.                 nCount := i - PaceBaseOne;
  5.                 if (nCount > -1) then begin
  6.                         nCountr := i / 7;
  7.                         if (Length(TArr1) = 0) then SetLength(TArr1, Length(TArr1) + 1);
  8.                         if (nCountr = RR(nCountr)) then bool1 := True;
  9.                         if Self.IsBitSet(num[RR(i / 8)], i) then Self.SetBit(TArr1[RR(nCount / 8)], nCount);
  10.                 end;
  11.                 if bool1 then SetLength(TArr1, Length(TArr1) + 1);
  12.                 bool1 := False;
  13.         end;
  14.         bool1 := True;
  15. end else begin
  16.         // more code
  17. end;
  18.  

This still exits the function/procedure
Then the Length of your num-array is zero

No, try this simple code
It exits the function/procedure
Code: Pascal  [Select][+][-]
  1.   SetLength ( TArr1, 1 );
  2.   TArr1 [ 0 ] := 0;
  3.   for i := 0 to ((8*Length(TArr1))-1) do begin
  4.     //nothing...
  5.   end;  
  6.  

Zvoni

  • Hero Member
  • *****
  • Posts: 3305
Re: Lazarus/FreePascal Bug
« Reply #6 on: February 13, 2026, 10:07:22 am »
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$mode ObjFPC}{$H+}
  3. Var
  4.   TArr1:Array Of Byte;
  5.   i:Integer;
  6. begin
  7.   SetLength ( TArr1, 1 );
  8.   TArr1 [ 0 ] := 0;
  9.   for i := 0 to ((8*Length(TArr1))-1) do begin
  10.     Writeln('Iteration ',i, ' - Value=',Tarr1[0]);
  11.   end;
  12.   Readln;
  13. end.
  14.  

Returns
Quote
Iteration 0 - Value=0
Iteration 1 - Value=0
Iteration 2 - Value=0
Iteration 3 - Value=0
Iteration 4 - Value=0
Iteration 5 - Value=0
Iteration 6 - Value=0
Iteration 7 - Value=0
If your Code never executes the body of the For-Loop then the Length of your num-array is zero
« Last Edit: February 13, 2026, 10:09:55 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

JgQDev

  • New member
  • *
  • Posts: 9
Re: Lazarus/FreePascal Bug
« Reply #7 on: February 13, 2026, 10:15:31 am »
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$mode ObjFPC}{$H+}
  3. Var
  4.   TArr1:Array Of Byte;
  5.   i:Integer;
  6. begin
  7.   SetLength ( TArr1, 1 );
  8.   TArr1 [ 0 ] := 0;
  9.   for i := 0 to ((8*Length(TArr1))-1) do begin
  10.     Writeln('Iteration ',i, ' - Value=',Tarr1[0]);
  11.   end;
  12.   Readln;
  13. end.
  14.  

Returns
Quote
Iteration 0 - Value=0
Iteration 1 - Value=0
Iteration 2 - Value=0
Iteration 3 - Value=0
Iteration 4 - Value=0
Iteration 5 - Value=0
Iteration 6 - Value=0
Iteration 7 - Value=0
If your Code never executes the body of the For-Loop then the Length of your num-array is zero

Okay wait, what FPC and Lazarus IDE version you're using?
maybe I'm the problem

Zvoni

  • Hero Member
  • *****
  • Posts: 3305
Re: Lazarus/FreePascal Bug
« Reply #8 on: February 13, 2026, 10:19:55 am »
Okay wait, what FPC and Lazarus IDE version you're using?
maybe I'm the problem
FINALLY!!!
This should be the FIRST information you give out

Me: FPC3.2.3 (fixes)/Lazarus4.3 (Fixes) - Both 64Bit on Win10-64Bit
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

JgQDev

  • New member
  • *
  • Posts: 9
Re: Lazarus/FreePascal Bug
« Reply #9 on: February 13, 2026, 10:24:58 am »
Yeah, I'm the problem. I will update my FPC and Lazarus IDE. Thanks

cdbc

  • Hero Member
  • *****
  • Posts: 2671
    • http://www.cdbc.dk
Re: Lazarus/FreePascal Bug
« Reply #10 on: February 13, 2026, 10:52:58 am »
Hi
For what it's worth...  I like your formatting @JgQDev  8-)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Bart

  • Hero Member
  • *****
  • Posts: 5706
    • Bart en Mariska's Webstek
Re: Lazarus/FreePascal Bug
« Reply #11 on: February 13, 2026, 06:27:28 pm »
Me: FPC3.2.3 (fixes)/Lazarus4.3 (Fixes) - Both 64Bit on Win10-64Bit
As expected Zvoni's code behaves the same in fpc 3.2.4RC and fpc main (3.3.1).
The Lazarus version should not matter at all.

Bart

 

TinyPortal © 2005-2018