[DMD 1.027] dynamic array out-of-bounds

Bill Baxter dnewsgroup at billbaxter.com
Wed Feb 20 10:05:22 PST 2008


Keir wrote:
> I expected the following to blow up with horrid results, but it seems to 
> truck along just fine.
> 
> //{BeginCode}//////////////////////////////////////////////////
> import std.stdio;
> 
> void main()
>   {
>   int[] arr;
>   arr.length = (3*6);
> 
>   arr[3] = 3;
>   arr[4] = 4;
>   arr[5] = 5;
>   arr[10] = 10;
>   arr[18] = 18;  // expected runtime arraybounds error here
>   arr[19] = 19;
>   arr[20] = 20;
>   arr[21] = 21;
>   arr[22] = 22;
>   arr[30] = 30;
> 
>   // should overwrite ~some~thing important, yes?
>   for ( int i;i<arr.length*10;i++)
>     arr[i]=i+1;
> 
>   // expected arr[18] to throw the arraybounds error
>   for ( int i;i<31*5;i++)
>     writefln("%s [%s]",i,arr[i]);   
>   }

Did you compile with -debug?
I don't recall exactly, but I think that may be required to turn on 
array bounds checking.

--bb


More information about the Digitalmars-d-bugs mailing list