pgsql: Add static assertion that RELSEG_SIZE fits 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: Add static assertion that RELSEG_SIZE fits in an int.
Date: 2025-10-19 22:29:02
Message-ID: E1vAbte-002WDe-07@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add static assertion that RELSEG_SIZE fits in an int.

Our configure script intended to ensure this, but it supposed that
expr(1) would report an error for integer overflow. Maybe that
was true when the code was written (commit 3c6248a82 of 2008-05-02),
but all the modern expr's I tried will deliver bigger-than-int32
results without complaint. Moreover, if you use --with-segsize-blocks
then there's no check at all.

Ideally we'd add a test in configure itself to check that the value
fits in int, but to do that we'd need to suppose that test(1) handles
bigger-than-int32 numbers correctly. Probably modern ones do, but
that's an assumption I could do without; and I'm not too trusting
about meson either. Instead, let's install a static assertion, so
that even people who ignore all the compiler warnings you get from
such values will be forced to confront the fact that it won't work.

This has been hazardous for awhile, but given that we hadn't heard
a complaint about it till now, I don't feel a need to back-patch.

Reported-by: Casey Shobe <casey(dot)allen(dot)shobe(at)icloud(dot)com>
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/C5DC82D6-C76D-4E8F-BC2E-DF03EFC4FA24@icloud.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/92cf557ffae436235cfa3bbba1265b5807a68ef2

Modified Files
--------------
src/backend/storage/smgr/md.c | 10 ++++++++++
1 file changed, 10 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2025-10-20 00:36:06 pgsql: pg_checksums: Use new routine to retrieve data of PG_VERSION
Previous Message Tom Lane 2025-10-19 18:37:15 pgsql: Don't rely on zlib's gzgetc() macro.