When statically casting a Derived* in unallocated memory to a Base*, gcc's ASAN reports:
ASAN:DEADLYSIGNAL ================================================================= ==12829==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x563da3783776 bp 0x7ffde1670e50 sp 0x7ffde166d800 T0) ==12829==The signal is caused by a READ memory access. ==12829==Hint: address points to the zero page.
For the test I used this setup:
struct Base2 { int dummy; };
struct Base { int dummy2; };
struct Derived : public Base2, public virtual Base { };
Derived* derived = (Derived*)0x1122334455667788; /* some pointer into non-allocated memory */
Base* base = static_cast<Base*>(derived); /* ASAN fails here */
Why does ASAN report an invalid read access here? Shouldn't the pointer offset and therefore the correct resulting pointer value be known at compile time?
So why is this read access even necessary?
Aucun commentaire:
Enregistrer un commentaire