www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Operations on all array elements => access to memory outside array

reply "fded" <fded.cmlxxiv gmail.com> writes:
I tested this code:

import std.stdio;

void main(){
	double[] a=[1,2];
	double[10] c;
	c[]=a[]+0.;
	writeln(c);
	double[] b=[1,2,3,4,5,6,7,8,9,10];
	double[10] d;
	double[] e=b[0..2];
	d[]=e[]+0.;	
	writeln(e);
	writeln(d);
	d[]=e[];	
}

with the following result:

[1, 2, 0, 1.28823e-231, 1.11255e-308, -1.43745e+306, 0, 
1.28823e-231, 1.56648e-307, 0]
[1, 2]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
object.Exception src\rt\arraycat.d(31): lengths don't match for 
array copy
----------------
415330
4151BB
406DC4
406DFE
406A1F
41C425
----------------

Unless I have missed something, it seems that:

= tests the length of the array and implies an exception

BUT:

+ does not test the length, and it is thus possible to read 
information which are not allowed...


For information, I was testing how []+ were handling smaller 
array (e.g. Error? completed with nan? completed with 0.? cyclic 
computation?)
Jul 16 2012
parent reply "fded" <fded.cmlxxiv gmail.com> writes:
I used:

DMD32 D Compiler v2.059

on windows 7.

On Monday, 16 July 2012 at 18:24:36 UTC, fded wrote:
 I tested this code:

 For information, I was testing how []+ were handling smaller 
 array (e.g. Error? completed with nan? completed with 0.? 
 cyclic computation?)

Jul 16 2012
parent "Daniel Murphy" <yebblies nospamgmail.com> writes:
"fded" <fded.cmlxxiv gmail.com> wrote in message 
news:jjxlvtkcohzeseqbixms forum.dlang.org...
I used:

 DMD32 D Compiler v2.059

 on windows 7.

 On Monday, 16 July 2012 at 18:24:36 UTC, fded wrote:
 I tested this code:

 For information, I was testing how []+ were handling smaller array (e.g. 
 Error? completed with nan? completed with 0.? cyclic computation?)


Please use the bug tracker instead of posting to this newsgroup directly. http://d.puremagic.com/issues/ At a guess, I would say this is bug 2547. http://d.puremagic.com/issues/show_bug.cgi?id=2547
Jul 17 2012