Code security: "auto" / Reason for errors

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Wed Jun 1 08:34:12 PDT 2016


On Wednesday, 2 March 2016 at 19:42:02 UTC, Ozan wrote:
> Hi
>
> I despair of "auto var1 = var2"for arrays. Isn't it a open door 
> for errors. Example
>
> import std.stdio;
>
> void main()
> {
> 	int[] a;
> 	foreach(i; 0..10) a ~= i;
> 	auto b = a; // correct dlang coding: auto b = a.dup;
> 	
> 	a[2] = 1;
> 	b[2] = 5; // Overwrites assignment before
> 	writeln(a);
> 	writeln(b); // Always a == b but developer would like to have 
> (a != b)
> }
>
> The behaviour is different to other non-container datatypes.
> So in a first view, it looks like a data copy but it's only a 
> pointer copy.
>
> Regards, Ozan

Everything behaves as designed, auto changes nothing in the 
example and there is no security concern.

We have a bingo.



More information about the Digitalmars-d mailing list