Segfault with std.container.Array but not regular dynamic array

Dan dbdavidson at yahoo.com
Wed Nov 28 10:08:58 PST 2012


On Wednesday, 28 November 2012 at 13:43:04 UTC, Maxim Fomin wrote:
> On Wednesday, 28 November 2012 at 13:09:36 UTC, Dan wrote:

> Actually bug is still there - changing unittest to main() does 
> not fix program, even if it seems to run correctly. The problem 
> with memory corruption is that it may happen with no observable 
> segfaults just because erroneous operation was performed on 
> memory which was permitted to be read/written.
>
> Valgrind is tool which may show absence of memory corruption 
> errors. Giving your example:

Thanks! I see what you are saying in valgrind. However, the 
following shows no problem in valgrind. Same code, only using S 
instead of RefCounted!(int).
How could that be explained?
Note that both RefCount!() and your posted S have opAssign, 
whereas the one below does not. Perhaps it is a problem only when 
there exists a custom opAssign?


Thanks
Dan

---------
import std.typecons;
import std.stdio;
import pprint.pp;

struct S {
   int x;
   char[] c;
}
//alias RefCounted!(int) Foo;
alias S Foo;
Foo[int] map;

Foo f;

unittest {
   int i=3;
   map[i] = Foo();
}


More information about the Digitalmars-d-learn mailing list