[phobos] custom BlkAttr flags
Steve Schveighoffer
schveiguy at yahoo.com
Tue Jul 13 12:28:01 PDT 2010
----- Original Message ----
> From: Walter Bright <walter at digitalmars.com>
>
>
>
> 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.
That is no longer a requirement with the new array append functionality. All
that is required is that the end of an array is at the end of the "allocated"
data (that is, data that has been requested from the array append routines).
-Steve
More information about the phobos
mailing list