pgsql: Produce compiler errors if errno is referenced inside elog/erepo

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Produce compiler errors if errno is referenced inside elog/erepo
Date: 2018-08-11 15:24:06
Message-ID: E1foVkM-0006pJ-GA@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2018-08-11 19:53:28 pgsql: Fix wrong order of operations in inheritance_planner.
Previous Message Andrew Dunstan 2018-08-10 20:09:48 pgsql: Revert changes in execMain.c from commit 16828d5c0273b