public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: David Rowley <[email protected]>
Cc: Peter Eisentraut <[email protected]>
Cc: Masahiko Sawada <[email protected]>
Cc: [email protected]
Subject: Re: pgsql: pg_logicalinspect: Fix possible crash when passing a directory p
Date: Wed, 16 Jul 2025 10:56:20 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAApHDvrFdXjbrV6KCx_GHKYSufUbNDYSsjppcJQiGOURfJE6qg@mail.gmail.com>
References: <[email protected]>
	<CAApHDvqrhFfnetbcwgGkJ=z63T8HfQ_OyP=vX8BYiXyxFKt67w@mail.gmail.com>
	<[email protected]>
	<CAApHDvqf4tKwE0oP8ybL2Eu-SD=C34pdZ9vVDSJwvqDXi88nUg@mail.gmail.com>
	<[email protected]>
	<CAApHDvrFdXjbrV6KCx_GHKYSufUbNDYSsjppcJQiGOURfJE6qg@mail.gmail.com>

[ this thread was referenced recently, bringing it back top-of-mind ]

David Rowley <[email protected]> writes:
> On Thu, 13 Mar 2025 at 21:33, Peter Eisentraut <[email protected]> wrote:
>> Is there a way to reshuffle those conditionals to make this actually do
>> something useful on MSVC?

> I've just been experimenting with this and it seems the problem isn't
> with pg_unreachable(), it's with the compiler not understanding that
> the particular pg_unreachable() is always reached.

> What's happening is down to the multi-eval protection code for elevel
> in ereport_domain().  Because elevel is assigned to the variable
> "elevel_" the compiler seems to lose its proof that the
> pg_unreachable() is always reached.  Adjusting that condition to use
> the elevel parameter directly makes the warning disappear.

Looking again at the code for ereport_domain(), I wondered if
something like this would help MSVC see through it:

 #define ereport_domain(elevel, domain, ...)    \
    do { \
        const int elevel_ = (elevel); \
+       const bool is_error_ = (elevel_ >= ERROR); \
        pg_prevent_errno_in_scope(); \
        if (errstart(elevel_, domain)) \
            __VA_ARGS__, errfinish(__FILE__, __LINE__, __func__); \
-       if (elevel_ >= ERROR) \
+       if (is_error_) \
            pg_unreachable(); \
    } while(0)

This preserves single evaluation of the elevel parameter, and
perhaps it'd move the needle on whether the compiler thinks
is_error_ is a compile-time constant.  I'm just guessing
though, don't have this compiler to test with.

			regards, tom lane





view thread (16+ 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], [email protected], [email protected]
  Subject: Re: pgsql: pg_logicalinspect: Fix possible crash when passing a directory p
  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