Fix various instances of undefined behavior
John Naylor <john.naylor@postgresql.org>
Author:
John Naylor <john.naylor@postgresql.org>
Date: 2026-02-04T11:09:35Z
Releases:
19 (unreleased)
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
Files
| Path | Change | +/− |
|---|---|---|
| contrib/pg_trgm/trgm_gist.c | modified | +4 −1 |
| src/backend/access/heap/heaptoast.c | modified | +1 −1 |
| src/backend/utils/adt/multirangetypes.c | modified | +3 −2 |
| src/backend/utils/sort/sharedtuplestore.c | modified | +2 −1 |
Discussion
- Undefined behavior detected by new clang's ubsan 12 messages · 2026-01-20 → 2026-02-04