pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid assuming that time_t can fit in an int.
Date: Wed, 22 Oct 2025 21:50:24 +0000
Message-ID: <E1vBgiu-003111-2B@gemulon.postgresql.org> (raw)

Avoid assuming that time_t can fit in an int.

We had several places that used cast-to-unsigned-int as a substitute
for properly checking for overflow.  Coverity has started objecting
to that practice as likely introducing Y2038 bugs.  An extra
comparison is surely not much compared to the cost of time(NULL), nor
is this coding practice particularly readable.  Let's do it honestly,
with explicit logic covering the cases of first-time-through and
clock-went-backwards.

I don't feel a need to back-patch though: our released versions
will be out of support long before 2038, and besides which I think
the code would accidentally work anyway for another 70 years or so.

Branch
------
master

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

Modified Files
--------------
src/backend/postmaster/pgarch.c            | 30 +++++++++++++++++-------------
src/backend/postmaster/postmaster.c        | 16 ++++++++++++----
src/backend/replication/logical/slotsync.c | 26 ++++++++++++++++----------
3 files changed, 45 insertions(+), 27 deletions(-)



Message-ID: <E1vBgiu-003111-2B@gemulon.postgresql.org>
Permalink:  ../E1vBgiu-003111-2B@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1vBgiu-003111-2B@gemulon.postgresql.org

 · 

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: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Avoid assuming that time_t can fit in an int.
  In-Reply-To: <E1vBgiu-003111-2B@gemulon.postgresql.org>

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

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