pgsql: Produce compiler errors if errno is referenced insideelog/erepo - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Produce compiler errors if errno is referenced insideelog/erepo
Date
Msg-id E1foVkM-0006pJ-GA@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Produce compiler errors if errno is referenced inside elog/ereport calls.

It's often unsafe to reference errno within an elog/ereport call, because
there are a lot of sub-functions involved and they might not all preserve
errno.  (This is why we support the %m format spec: it works off a value
of errno captured before we execute any potentially-unsafe functions in
the arguments.)  Therefore, we have a project policy not to use errno
there.

This patch adds a hack to cause an (admittedly obscure) compiler error
for such unsafe usages.  With the current code, the error will only be seen
on Linux, macOS, and FreeBSD, but that should certainly be enough to catch
mistakes in the buildfarm if they somehow get missed earlier.

In addition, fix some places in src/common/exec.c that trip the error.
I think these places are actually all safe, but it's simple enough to
avoid the error by capturing errno manually, and doing so is good
future-proofing in case these call sites get any more complicated.

Thomas Munro (exec.c fixes by me)

Discussion: https://postgr.es/m/2975.1526862605@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a2a8acd15217b1e355c083a41da4dc5c7f35b30b

Modified Files
--------------
src/common/exec.c        | 27 +++++++++++++++++++++------
src/include/utils/elog.h | 21 +++++++++++++++++++++
2 files changed, 42 insertions(+), 6 deletions(-)


pgsql-committers by date:

Previous
From: Andrew Dunstan
Date:
Subject: pgsql: Revert changes in execMain.c from commit 16828d5c0273b
Next
From: Tom Lane
Date:
Subject: pgsql: Fix wrong order of operations in inheritance_planner.