Re: warning: dereferencing type-punned pointer - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: warning: dereferencing type-punned pointer
Date
Msg-id fbfe2471-a001-49a6-a15b-3cb33b63e16f@eisentraut.org
Whole thread Raw
In response to Re: warning: dereferencing type-punned pointer  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: warning: dereferencing type-punned pointer
Re: warning: dereferencing type-punned pointer
List 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 by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: [18] Policy on IMMUTABLE functions and Unicode updates
Next
From: Tom Lane
Date:
Subject: Re: warning: dereferencing type-punned pointer