[Issue 14033] runtime error about "auto ptr = cast(T*)buf" , T is class type
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Jan 23 07:30:59 PST 2015
https://issues.dlang.org/show_bug.cgi?id=14033
ag0aep6g at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |ag0aep6g at gmail.com
Resolution|--- |INVALID
--- Comment #2 from ag0aep6g at gmail.com ---
This is expected.
`clsPtr.a` does two dereferences:
1) `clsPtr` is dereferenced and yields a `clsTest` object. Class objects are
references (pointers) themselves. Since `buf` is all zeroes, you get a null
Object.
2) To access the `a` field, that null reference is then dereferenced. Boom,
segfault.
In code:
clsTest tmp = *clsPtr;
/* tmp is null */
tmp.a = 123; /* dereferencing null */
Closing as invalid.
--
More information about the Digitalmars-d-bugs
mailing list