View Issue Details

IDProjectCategoryView StatusLast Update
0037112FPCCompilerpublic2020-05-20 09:54
Reporter440bx Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platformprobably independentOSWindows 
Product Version3.0.4 
Summary0037112: FPC does not do range checks on boolean arrays consisting of one element.
Descriptionif an array consisting of one boolean element is indexed outside the one element, the compiler does not emit a warning nor error. See sample program, the compiler should emit a warning or an error. Note: the presence or absence of $R+ does not affect the compilation in any way in this case.

{$APPTYPE CONSOLE}
{$R+}

program BooleanRangeChecks;

type
  TARRAY_BOOLEAN_TYPE = array[true..true] of integer;
  TARRAY_INTEGER_TYPE = array[1 .. 5] of integer;

var
  BooleanArray : TARRAY_BOOLEAN_TYPE;
  IntegerArray : TARRAY_INTEGER_TYPE;

  IntegerVariable : integer;


begin
  IntegerVariable := 1;

  { no warning about index being out of range }
  { or use "false" instead of an expression }

  BooleanArray[1 > 2] := IntegerVariable;

  writeln(BooleanArray[low(BooleanArray)]);
end.
Steps To Reproducecompile the sample program
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Serge Anvarov

2020-05-19 21:05

reporter   ~0122941

Moreover, it generates code that places the value outside the array boundaries. As a result, the program produces sigsegv.

Sven Barth

2020-05-20 09:54

manager   ~0122948

The generated code is not the problem. That the compiler allows out of bound access is by design. However that it doesn't warn (or error in case of $R+) is the problem.

Issue History

Date Modified Username Field Change
2020-05-19 09:35 440bx New Issue
2020-05-19 21:05 Serge Anvarov Note Added: 0122941
2020-05-20 09:54 Sven Barth Note Added: 0122948