Re: warning: dereferencing type-punned pointer

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Tatsuo Ishii <ishii(at)postgresql(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: warning: dereferencing type-punned pointer
Date: 2024-07-24 17:53:47
Message-ID: 1fe7031f-3a25-40c3-b244-530ea42fc133@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2024-07-24 18:01:01 Re: proposal: schema variables
Previous Message Tom Lane 2024-07-24 17:48:08 Re: warning: dereferencing type-punned pointer