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

Comments

  1. Did you check "Range checking" checkbox in compiler options ?

    ReplyDelete
  2. DOH! I assumed it was on - it was off :P

    ReplyDelete
  3. Lars 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.

    ReplyDelete
  4. Range Checking ( http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Range_checking ) is defaulted as off :-(

    To 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).

    ReplyDelete
  5. Turns out I already upvoted this :P

    ReplyDelete
  6. There were discussions in the pre and post Wasabi eras about this. Yada Yada Yada backward compatibity Yada Yada Yada.

    I think there are RAID and QC issues for this as well that I upvoted.

    ReplyDelete

Post a Comment