pgsql: Fix various instances of undefined behavior

From: John Naylor <john(dot)naylor(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix various instances of undefined behavior
Date: 2026-02-04 11:09:09
Message-ID: E1vnaku-0015MF-2Z@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix various instances of undefined behavior

Mostly this involves checking for NULL pointer before doing operations
that add a non-zero offset.

The exception is an overflow warning in heap_fetch_toast_slice(). This
was caused by unneeded parentheses forcing an expression to be
evaluated to a negative integer, which then got cast to size_t.

Per clang 21 undefined behavior sanitizer.

Backpatch to all supported versions.

Co-authored-by: Alexander Lakhin <exclusion(at)gmail(dot)com>
Reported-by: Alexander Lakhin <exclusion(at)gmail(dot)com>
Discussion: https://postgr.es/m/777bd201-6e3a-4da0-a922-4ea9de46a3ee@gmail.com
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/73ac2b37401d7aa910ebd81795bb0f4faf0eaab3

Modified Files
--------------
contrib/pg_trgm/trgm_gist.c | 5 ++++-
src/backend/access/heap/heaptoast.c | 2 +-
src/backend/utils/adt/multirangetypes.c | 5 +++--
src/backend/utils/sort/sharedtuplestore.c | 3 ++-
4 files changed, 10 insertions(+), 5 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message John Naylor 2026-02-04 11:11:23 pgsql: Fix various instances of undefined behavior
Previous Message Heikki Linnakangas 2026-02-04 11:08:18 pgsql: Add backendType to PGPROC, replacing isRegularBackend