Edit: Nevermind - RangeCheck was off.
Edit: Nevermind - RangeCheck was off.
Should this code create an Index out of bounds error?
type
TArrayType = TArray;
procedure TSomeClass.GetArray(var anArray: TArrayType);
begin
SetLength(anArray, 10);
for ix := 1 to 10 // Should have been 0 to 9
do anArray[ix]:= ix; // <<-- Index out of bounds but no error
end;
procedure Test(SomeClassInst: TSomeClass);
var
Arr: TArray;
begin
SomeClassInst.GetArray(Arr);
// do something
end; <<-- Eurekalog flags overwrite on array finalization
Should this code create an Index out of bounds error?
type
TArrayType = TArray
procedure TSomeClass.GetArray(var anArray: TArrayType);
begin
SetLength(anArray, 10);
for ix := 1 to 10 // Should have been 0 to 9
do anArray[ix]:= ix; // <<-- Index out of bounds but no error
end;
procedure Test(SomeClassInst: TSomeClass);
var
Arr: TArray
begin
SomeClassInst.GetArray(Arr);
// do something
end; <<-- Eurekalog flags overwrite on array finalization
What are you expecting? It produces an Execption for me.
ReplyDelete** EDIT ** With "{$RANGECHECKS ON}"
pastebin.com - [Pascal] uses SysUtils; type TArrayType = TArray; procedure GetArray - Pastebin.com
Did you check "Range checking" checkbox in compiler options ?
ReplyDeleteDOH! I assumed it was on - it was off :P
ReplyDeleteLars Fosdal the defaults often confuse me too as I hardly start with a fresh new program, so I tend to forget what I have changed.
ReplyDeleteRange Checking ( http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Range_checking ) is defaulted as off :-(
ReplyDeleteTo me, it seems like something that should be something that is defaulted on (even if there is a performance hit - maybe on for Debug and off for Release).
https://quality.embarcadero.com/browse/RSP-16751
ReplyDeleteTurns out I already upvoted this :P
ReplyDeleteFor a reason obviously ;)
ReplyDeleteStefan Glienke Indeed ;)
ReplyDeleteThere were discussions in the pre and post Wasabi eras about this. Yada Yada Yada backward compatibity Yada Yada Yada.
ReplyDeleteI think there are RAID and QC issues for this as well that I upvoted.