Re: warning: dereferencing type-punned pointer

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: warning: dereferencing type-punned pointer
Дата
Msg-id fbfe2471-a001-49a6-a15b-3cb33b63e16f@eisentraut.org
обсуждение исходный текст
Ответ на Re: warning: dereferencing type-punned pointer  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: warning: dereferencing type-punned pointer
Re: warning: dereferencing type-punned pointer
Список pgsql-hackers
On 24.07.24 20:09, Tom Lane wrote:
> Peter Eisentraut<peter@eisentraut.org>  writes:
>> On 24.07.24 16:05, Tom Lane wrote:
>>> I'm not very thrilled with these changes.  It's not apparent why
>>> your compiler is warning about these usages of IsA and not any other
>>> ones,
>> I think one difference is that normally IsA is called on a Node * (since
>> you call IsA to decide what to cast it to), but in this case it's called
>> on a pointer that is already of type ErrorSaveContext *.
> Hmm.  But there are boatloads of places where we call IsA on a
> pointer of type Expr *, or sometimes other things.  Why aren't
> those triggering the same warning?

It must have to do with the fact that the escontext field in 
JsonExprState has the object inline, not as a pointer.  AIUI, with 
dynamically allocated objects you have more liberties about what type to 
interpret them as than with actually declared objects.

If you change the member to a pointer

-   ErrorSaveContext escontext;
+   ErrorSaveContext *escontext;
  } JsonExprState;

and make the required adjustments elsewhere in the code, the warning 
goes away.

This arrangement would also appear to be more consistent with other 
executor nodes (e.g., ExprState, ExprEvalStep), so it might be worth it 
for consistency in any case.




В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: [18] Policy on IMMUTABLE functions and Unicode updates
Следующее
От: Tom Lane
Дата:
Сообщение: Re: warning: dereferencing type-punned pointer