public inbox for [email protected]
help / color / mirror / Atom feedFrom: David Rowley <[email protected]>
To: Tom Lane <[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: Thu, 17 Jul 2025 16:09:18 +1200
Message-ID: <CAApHDvp-WCUTDU767Lpjw3m698gS+mCrNAnTEppZiXixneVxGQ@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
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>
<[email protected]>
<CAApHDvoOnd4PBNV0qyJVLmbWvWUjztzcMH5xY2AGp5Vov6XU3Q@mail.gmail.com>
<[email protected]>
On Thu, 17 Jul 2025 at 15:19, Tom Lane <[email protected]> wrote:
>
> David Rowley <[email protected]> writes:
> > I spent a bit more time searching for a solution and did find
> > something that works well enough for this case in [1]. Unfortunately,
> > it only works with C11. See attached .c file and output below.
>
> Hmph. I doubt we are ready to require C11 everywhere, but maybe
> we could require it in MSVC builds? Which MSVC versions would
> that eliminate?
Going by [1] it's Visual Studio 2019, which as of 8fd9bb1d9 is now our
minimum supported VS version.
I hacked up a quick patch (attached) which compiles without any
warnings. Tested on VS2012 with meson setup -Dc_std=c11.
Unsure what other repercussions there are of compiling with C11 and
have not looked into what it would take to adjust the meson build
scripts to default to that for MSVC builds.
David
[1] https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/
Attachments:
[application/octet-stream] v1-0001-Detect-elog-ERROR-can-t-return-in-MSVC-when-using.patch (1.8K, 2-v1-0001-Detect-elog-ERROR-can-t-return-in-MSVC-when-using.patch)
download | inline diff:
From e4ced93b2c35db91cb28f564103a7238efd72b43 Mon Sep 17 00:00:00 2001
From: David Rowley <[email protected]>
Date: Thu, 17 Jul 2025 15:49:03 +1200
Subject: [PATCH v1] Detect elog(ERROR) can't return in MSVC when using C11
---
src/backend/backup/basebackup_target.c | 2 +-
src/include/utils/elog.h | 16 +++++++++++++++-
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/backend/backup/basebackup_target.c b/src/backend/backup/basebackup_target.c
index 84b1309d3bd..0b48521f104 100644
--- a/src/backend/backup/basebackup_target.c
+++ b/src/backend/backup/basebackup_target.c
@@ -146,7 +146,7 @@ BaseBackupGetTargetHandle(char *target, char *target_detail)
errmsg("unrecognized target: \"%s\"", target)));
/* keep compiler quiet */
- return NULL;
+ //return NULL;
}
/*
diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h
index 675f4f5f469..c93ba82ecf8 100644
--- a/src/include/utils/elog.h
+++ b/src/include/utils/elog.h
@@ -137,7 +137,21 @@ struct Node;
* prevents gcc from making the unreachability deduction at optlevel -O0.
*----------
*/
-#ifdef HAVE__BUILTIN_CONSTANT_P
+
+#if defined(_MSC_VER) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112
+#define pg_builtin_constant(x) \
+ _Generic((1 ? ((void*)((x)*(uintptr_t)0)) : &(int){1}), int*: 1, void*: 0)
+#define ereport_domain(elevel, domain, ...) \
+ do { \
+ pg_prevent_errno_in_scope(); \
+ if (pg_builtin_constant(elevel) && (elevel) >= ERROR ? \
+ errstart_cold(elevel, domain) : \
+ errstart(elevel, domain)) \
+ __VA_ARGS__, errfinish(__FILE__, __LINE__, __func__); \
+ if (pg_builtin_constant(elevel) && (elevel) >= ERROR) \
+ pg_unreachable(); \
+ } while(0)
+#elif defined(HAVE__BUILTIN_CONSTANT_P)
#define ereport_domain(elevel, domain, ...) \
do { \
pg_prevent_errno_in_scope(); \
--
2.40.1.windows.1
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: <CAApHDvp-WCUTDU767Lpjw3m698gS+mCrNAnTEppZiXixneVxGQ@mail.gmail.com>
* 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