pgsql: Fix various instances of undefined behavior - Mailing list pgsql-committers

From John Naylor
Subject pgsql: Fix various instances of undefined behavior
Date
Msg-id E1vnan4-0015P2-2V@gemulon.postgresql.org
Whole thread Raw
List 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@gmail.com>
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/777bd201-6e3a-4da0-a922-4ea9de46a3ee@gmail.com
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/176dffdf7d2a0ea2615c4e390a2ab7e69d14f90f

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


pgsql-committers by date:

Previous
From: John Naylor
Date:
Subject: pgsql: Fix various instances of undefined behavior
Next
From: Fujii Masao
Date:
Subject: pgsql: Fix logical replication TAP test to read publisher log correctly