Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2026-10

looks like a bug

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

P Padil

I set a small array and the program below is ok to go out of bounds.

—
program test;
type
   tarr = array of array of boolean;
var
  exa : tarr = ((false,false,true,true),(false,false,true,true),
  (true,true,false,true), (true,true,true,false));

begin

  writeln(exa[0,0],', ',exa[4,4]);
  writeln(low(exa),', ',high(exa));
  writeln(low(exa[4]),', ',high(exa[4]));

end.
—
Free Pascal Compiler version 3.2.2 [2024/09/11] for aarch64 Copyright (c) 1993-2021 by Florian Klaempfl and others Target OS: Darwin for AArch64
Compiling test.pp
Assembling test
Linking test
-macosx_version_min has been renamed to -macos_version_min ld: warning: -multiply_defined is obsolete
15 lines compiled, 0.3 sec
FALSE, TRUE
0, 3
0, 3

Regards
Pete

Unknown author
to P Padil
{$R+}  // range checking
{$Q+}  // overflow checking

----- Oorspronkelijk bericht -----
Van: "P Padil via fpc-pascal"
Aan: "discussions FPC-Pascal users"
Cc: "P Padil"
Verzonden: Maandag 19 oktober 2026 02:45:30
Onderwerp: [fpc-pascal] looks like a bug

I set a small array and the program below is ok to go out of bounds.

—
program test;
type
   tarr = array of array of boolean;
var
  exa : tarr = ((false,false,true,true),(false,false,true,true),
  (true,true,false,true), (true,true,true,false));

begin

  writeln(exa[0,0],', ',exa[4,4]);
  writeln(low(exa),', ',high(exa));
  writeln(low(exa[4]),', ',high(exa[4]));

end.
—
Free Pascal Compiler version 3.2.2 [2024/09/11] for aarch64 Copyright (c) 1993-2021 by Florian Klaempfl and others Target OS: Darwin for AArch64
Compiling test.pp
Assembling test
Linking test
-macosx_version_min has been renamed to -macos_version_min ld: warning: -multiply_defined is obsolete
15 lines compiled, 0.3 sec
FALSE, TRUE
0, 3
0, 3

Regards
Pete

P Padil
to Unknown author

I typically got an exception even w/o those flags. I might have gotten to complacent running w/o them set though.

Show quoted text 50 lines
On Oct 18, 2026, at 7:29 PM, wrote: {$R+} // range checking {$Q+} // overflow checking ----- Oorspronkelijk bericht ----- Van: "P Padil via fpc-pascal" Aan: "discussions FPC-Pascal users" Cc: "P Padil" Verzonden: Maandag 19 oktober 2026 02:45:30 Onderwerp: [fpc-pascal] looks like a bug I set a small array and the program below is ok to go out of bounds. — program test; type tarr = array of array of boolean; var exa : tarr = ((false,false,true,true),(false,false,true,true), (true,true,false,true), (true,true,true,false)); begin writeln(exa[0,0],', ',exa[4,4]); writeln(low(exa),', ',high(exa)); writeln(low(exa[4]),', ',high(exa[4])); end. — Free Pascal Compiler version 3.2.2 [2024/09/11] for aarch64 Copyright (c) 1993-2021 by Florian Klaempfl and others Target OS: Darwin for AArch64 Compiling test.pp Assembling test Linking test -macosx_version_min has been renamed to -macos_version_min ld: warning: -multiply_defined is obsolete 15 lines compiled, 0.3 sec FALSE, TRUE 0, 3 0, 3 Regards Pete _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Peter Blackman
to P Padil: I set a small array and the program below is ok to go out of bounds. — program test;…
P Padil wrote 17 lines
I set a small array and the program below is ok to go out of bounds. — program test; type tarr = array of array of boolean; var exa : tarr = ((false,false,true,true),(false,false,true,true), (true,true,false,true), (true,true,true,false)); begin writeln(exa[0,0],', ',exa[4,4]); writeln(low(exa),', ',high(exa)); writeln(low(exa[4]),', ',high(exa[4])); end.

As its a dynamic array, I would use SetLength on it, before assigning to its elements.

Cheers,
Peter

Sven Barth
to Peter Blackman

Peter Blackman via fpc-pascal schrieb am
Di., 20. Okt. 2026, 23:51:

Show quoted text 21 lines
On 19/10/2026 01:45, P Padil via fpc-pascal wrote: > I set a small array and the program below is ok to go out of bounds. > > — > program test; > > type > tarr = array of array of boolean; > > var > exa : tarr = ((false,false,true,true),(false,false,true,true), > (true,true,false,true), (true,true,true,false)); > > begin > writeln(exa[0,0],', ',exa[4,4]); > writeln(low(exa),', ',high(exa)); > writeln(low(exa[4]),', ',high(exa[4])); > end. As its a dynamic array, I would use SetLength on it, before assigning to its elements.

The array is already initialized with the initialization directly following its declaration. A SetLength() is not necessary in that case.

Regards,
Sven

Peter Blackman
to Sven Barth
Sven Barth wrote 33 lines
Peter Blackman via fpc-pascal < > schrieb am Di., 20. Okt. 2026, 23:51: On 19/10/2026 01:45, P Padil via fpc-pascal wrote: > I set a small array and the program below is ok to go out of bounds. > > — > program test; > > type >     tarr = array of array of boolean; > > var >    exa : tarr = ((false,false,true,true),(false,false,true,true), >    (true,true,false,true), (true,true,true,false)); > > begin >    writeln(exa[0,0],', ',exa[4,4]); >    writeln(low(exa),', ',high(exa)); >    writeln(low(exa[4]),', ',high(exa[4])); > end. As its a dynamic array, I would use SetLength on it, before assigning to its elements. The array is already initialized with the initialization directly following its declaration. A SetLength() is not necessary in that case. Regards, Sven _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

OK, but its initialised to 4x4.
0..4 is 5 I think.

Cheers,
Peter

Sven Barth
to Peter Blackman

Peter Blackman via fpc-pascal schrieb am
Mi., 21. Okt. 2026, 00:45:

Show quoted text 41 lines
On 20/10/2026 23:28, Sven Barth via fpc-pascal wrote: > Peter Blackman via fpc-pascal < <mailto: >> schrieb am Di., 20. Okt. 2026, 23:51: > > On 19/10/2026 01:45, P Padil via fpc-pascal wrote: > > I set a small array and the program below is ok to go out of bounds. > > > > — > > program test; > > > > type > > tarr = array of array of boolean; > > > > var > > exa : tarr = ((false,false,true,true),(false,false,true,true), > > (true,true,false,true), (true,true,true,false)); > > > > begin > > writeln(exa[0,0],', ',exa[4,4]); > > writeln(low(exa),', ',high(exa)); > > writeln(low(exa[4]),', ',high(exa[4])); > > end. > As its a dynamic array, I would use SetLength on it, > before assigning to its elements. > > > The array is already initialized with the initialization directly following its declaration. A SetLength() is not necessary in that case. > > Regards, > Sven > > > _______________________________________________ > fpc-pascal maillist - > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal OK, but its initialised to 4x4. 0..4 is 5 I think.

That is indeed the case. Hadn't seen noticed that the code accesses the data at index 4. ^^'

Regards,
Sven