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

From Peter Eisentraut
Subject Re: warning: dereferencing type-punned pointer
Date
Msg-id 1fe7031f-3a25-40c3-b244-530ea42fc133@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
List pgsql-hackers
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 *.  You wouldn't 
normally need to call IsA on that, but it comes with the 
SOFT_ERROR_OCCURRED macro.  Another difference is that most nodes are 
dynamically allocated but in this case the ErrorSaveContext object (not 
a pointer to it) is part of another struct, and so I think some 
different aliasing rules might apply, but I'm not sure.

I think here you could just bypass the SOFT_ERROR_OCCURRED macro:

-       if (SOFT_ERROR_OCCURRED(&jsestate->escontext))
+       if (jsestate->escontext.error_occurred)



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: warning: dereferencing type-punned pointer
Next
From: Pavel Stehule
Date:
Subject: Re: proposal: schema variables