pgsql: Avoid assuming that time_t can fit in an int.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid assuming that time_t can fit in an int.
Date: 2025-10-22 21:50:24
Message-ID: E1vBgiu-003111-2B@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message David Rowley 2025-10-23 00:11:22 pgsql: Fix incorrect zero extension of Datum in JIT tuple deform code
Previous Message Nathan Bossart 2025-10-22 21:48:02 pgsql: Fix type of infomask parameter in htup_details.h functions.