[cfe-dev] warnings in clang
Sebastian Redl
sebastian.redl at getdesigned.at
Fri Nov 14 15:33:40 PST 2008
Mike Stump wrote:
> On Nov 14, 2008, at 2:55 PM, Argiris Kirtzidis wrote:
>
>
>> D.ReadUIntPtr(reinterpret_cast<uintptr_t&>(MDC->SemanticDC),
>> SemaDCPtrID);
>>
>> where 'MDC->SemanticDC' is a pointer (DeclContext*).
>>
>
> reinterpret_cast<uintptr_t&>? Never use reinterpret_cast.
>
> uintptr_t x;
> D.ReadUIntPtr(x, SemaDCPtrID);
>
> will read a uintptr_t. This:
>
> MDC->SemanticDC = (DeclContext*)x;
>
> will convert and store it.
This would be highly dangerous, because the deserializer stores the
reference you pass it for backpatching. In other words, if you introduce
a local variable and give it to the deserializer with backpatching
enable, you're effectively creating a dangling reference.
Sebastian
More information about the cfe-dev
mailing list