1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
{$mode objfpc}
uses sysutils;
{$r+}
var
a1: array[-5..6] of byte;
a2: array[-12..-1] of byte;
a3: array[0..6] of byte;
a4: array[1..12] of byte;
c: cardinal;
l: longint;
b: byte;
finalerror: boolean;
function check_longint(l: longint; res1, res2, res3, res4: boolean): boolean;
var
caught,
error: boolean;
begin
result := false;
caught := false;
try
b := a1[l];
except
caught := true;
end;
error := caught <> res1;
if error then writeln('long 1 failed for ',l);
result := result or error;
caught := false;
try
b := a2[l];
except
caught := true;
end;
error := caught <> res2;
if error then writeln('long 2 failed for ',l);
result := result or error;
caught := false;
try
b := a3[l];
except
caught := true;
end;
error := caught <> res3;
if error then writeln('long 3 failed for ',l);
result := result or error;
caught := false;
try
b := a4[l];
except
caught := true;
end;
error := caught <> res4;
if error then writeln('long 4 failed for ',l);
result := result or error;
writeln;
end;
function check_cardinal(l: cardinal; res1, res2, res3, res4: boolean): boolean;
var
caught,
error: boolean;
begin
result := false;
caught := false;
try
b := a1[l];
except
caught := true;
end;
error := caught <> res1;
if error then writeln('card 1 failed for ',l);
result := result or error;
caught := false;
try
b := a2[l];
except
caught := true;
end;
error := caught <> res2;
if error then writeln('card 2 failed for ',l);
result := result or error;
caught := false;
try
b := a3[l];
except
caught := true;
end;
error := caught <> res3;
if error then writeln('card 3 failed for ',l);
result := result or error;
caught := false;
try
b := a4[l];
except
caught := true;
end;
error := caught <> res4;
if error then writeln('card 4 failed for ',l);
result := result or error;
writeln;
end;
begin
finalerror :=
check_longint(-1,false,false,true,true);
finalerror :=
check_longint(-6,true,false,true,true) or finalerror;
finalerror :=
check_longint(0,false,true,false,true) or finalerror;
finalerror :=
check_cardinal(0,false,true,false,true);
finalerror :=
check_cardinal(cardinal($ffffffff),true,true,true,true) or finalerror;
finalerror :=
check_cardinal(5,false,true,false,false) or finalerror;
if finalerror then
begin
writeln('Still errors in range checking for array indexes');
halt(1);
end;
end.
|