public inbox for [email protected]  
help / color / mirror / Atom feed
From: Peter Eisentraut <[email protected]>
To: Tom Lane <[email protected]>
Cc: Tatsuo Ishii <[email protected]>
Cc: [email protected]
Subject: Re: warning: dereferencing type-punned pointer
Date: Wed, 24 Jul 2024 20:26:55 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>

On 24.07.24 20:09, Tom Lane wrote:
> Peter Eisentraut<[email protected]>  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.







view thread (10+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: warning: dereferencing type-punned pointer
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox