[phobos] custom BlkAttr flags
Walter Bright
walter at digitalmars.com
Tue Jul 13 12:15:08 PDT 2010
Steve Schveighoffer wrote:
> Currently, there is a problem in the runtime which can result in very odd
> behavior. Let's say you declare a class like this:
>
> class C
> {
> int[1] x;
> }
>
> Now, let's say you do something like this:
>
> auto c = new C;
> auto x = c.x[];
> x ~= 1;
>
> What happens here? Well, the memory for c and c.x are on the heap, so the
> block allocated by c is considered for appending, and a "length" field is looked
> at, even though that length is possibly garbage. The result is that it's
> extremely improbable, but possible, that the append could happen in place if
> that "length" happens to be correct (thereby overwriting other members of c). I
> can't even begin to construct a case which shows this is possible, and it may
> not even be, but I think this needs attention.
>
>
It will never happen, as c.x[1] is not at the beginning of an allocated
block.
More information about the phobos
mailing list