Spec#, nullables and more

Leandro Lucarella luca at llucax.com.ar
Fri Nov 5 16:50:28 PDT 2010


Jesse Phillips, el  5 de noviembre a las 18:38 me escribiste:
> Leandro Lucarella Wrote:
> 
> > And then, you can corrupt memory with something like:
> > 
> > struct S {
> > 	int[1_000_000_000] data;
> > 	int far_data;
> > }
> > 
> > S* s = null;
> > s.far_data = 5;
> > 
> > If you are unlucky enough to end up in a valid address. That might not
> > be a practical example, of course, but theoretically null pointer could
> > lead to memory corruption.
> 
> Interesting, I get this:
> 
> test.d(13): Error: index 1000000000 overflow for static array
> 
> I'm not exactly sure what you are trying to demonstrate with it. Are
> you filling up the stack such that the OS tries to assign to a proper
> data field? How is it still not trying to access location 0 causing an
> Access Violation?

s.far_data = 5 is the same as *(s + S.far_data.sizeof) = 5, where
S.far_data.sizeof is 4_000_000_000 (i.e. 4 GB, I put a couple of extra
0 than I should :).

The point is, you're writing to a big address, which might be mapped to
your process, resulting in corrupted memory.

I think the error you are receiving is a compiler limitation, not
a language feature, but I might be wrong...

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Pa' ella cociné, pa' ella lavé, pa' ella soñe
Paella completa, $2,50
Pero, la luz mala me tira, y yo? yo soy ligero pa'l trote
La luz buena, está en el monte, allá voy, al horizonte


More information about the Digitalmars-d mailing list